#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
int oc[110];
int main() {
  int n, q, t, k, d, curt = 0, lib;
  scanf("%d %d ", &n, &q);
  lib = n;
  for (int i = 1; i < q + 1; i++) {
    scanf("%d %d %d ", &t, &k, &d);
    while (!pq.empty()) {
      pair<int, int> u = pq.top();
      pq.pop();
      if (u.first > t) {
        pq.push(u);
        break;
      }
      for (int j = 1; j < n + 1; j++)
        if (oc[j] == u.second) {
          oc[j] = 0;
          lib++;
        }
    }
    if (lib < k) {
      printf("-1\n");
      continue;
    }
    int res = 0;
    lib -= k;
    for (int j = 1; j < n + 1; j++)
      if (!oc[j]) {
        oc[j] = i;
        res += j;
        k--;
        if (!k) break;
      }
    pq.push(pair<int, int>(t + d, i));
    printf("%d\n", res);
  }
  return 0;
}
