#include <bits/stdc++.h>
using namespace std;
const int N = 111;
const int Q = 111111;
int s[N];
int t[Q], k[Q], d[Q];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) scanf("%d%d%d", t + i, k + i, d + i);
  for (int i = 0; i < q; i++) {
    int sum = 0;
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (s[j] < t[i]) cnt++;
    }
    if (k[i] > cnt)
      printf("-1\n");
    else {
      for (int j = 0; j < n; j++) {
        if (k[i] > 0 && s[j] < t[i]) {
          k[i]--;
          s[j] = t[i] + d[i] - 1;
          sum += j + 1;
        }
      }
      printf("%d\n", sum);
    }
  }
  return 0;
}
