#include <bits/stdc++.h>
int main() {
  int n, q;
  int t, k, d;
  int server[101];
  int free = 0;
  int sum = 0;
  memset(server, 0, sizeof(server));
  scanf("%d %d", &n, &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d", &t, &k, &d);
    for (int j = 1; j < n + 1; j++) {
      if (t >= server[j]) {
        free++;
      }
    }
    if (free < k) {
      printf("-1\n");
    } else {
      for (int j = 1; j < n + 1; j++) {
        if ((t >= server[j]) and k > 0) {
          server[j] = t + d;
          sum += j;
          k--;
        }
      }
      printf("%d\n", sum);
    }
    sum = 0;
    free = 0;
  }
  return 0;
}
