#include <bits/stdc++.h>
using namespace std;
struct Query {
  int k, t, d;
  Query() {}
  Query(int k, int t, int d) {
    this->k = k;
    this->t = t;
    this->d = d;
  }
};
const int N = 100;
const int Q = 1e5;
int busyuntil[N + 5];
Query qr[Q + 5];
bool operator<(Query a, Query b) { return a.t < b.t; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int ck, ct, cd;
    cin >> ct >> ck >> cd;
    qr[i] = Query(ck, ct, cd);
  }
  sort(qr, qr + q);
  for (int i = 0; i < q; i++) {
    int k = 0;
    for (int j = 0; j < n; j++) {
      if (busyuntil[j] <= qr[i].t) k++;
      if (k == qr[i].k) break;
    }
    if (k < qr[i].k) {
      cout << "-1\n";
      continue;
    }
    int ans = 0;
    for (int j = 0; j < n; j++) {
      if (busyuntil[j] <= qr[i].t) {
        busyuntil[j] = qr[i].t + qr[i].d;
        ans += j + 1;
        k--;
        if (k == 0) break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
