#include <bits/stdc++.h>
const int MAXN = 100007;
using namespace std;
int main() {
  int n, q;
  while (scanf("%d %d", &n, &q) != EOF) {
    int t[MAXN], k[MAXN], d[MAXN];
    int timespam = 0;
    int endtime[MAXN];
    memset(endtime, -1, sizeof(endtime));
    priority_queue<int> s;
    for (int i = 0; i < q; i++) {
      scanf("%d %d %d", &t[i], &k[i], &d[i]);
    }
    for (int i = 0; i < q; i++) {
      for (int j = 1; j <= n; j++) {
        if (endtime[j] < t[i] && endtime[j] != -2) {
          endtime[j] = -2;
          s.push(-j);
        }
      }
      int sum = 0;
      if (s.size() < k[i])
        sum = -1;
      else {
        for (int j = 0; j < k[i]; j++) {
          int id = abs(s.top());
          s.pop();
          sum += id;
          endtime[id] = t[i] + d[i] - 1;
        }
      }
      printf("%d\n", sum);
    }
  }
  return 0;
}
