#include <bits/stdc++.h>
using namespace std;
int Save[105];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  int cnt = 0;
  int t, k, d;
  long long sum = 0;
  while (q--) {
    scanf("%d%d%d", &t, &k, &d);
    vector<int> V;
    sum = 0;
    for (int j = 1; j <= n; j++) {
      if (Save[j] < t) {
        sum += j;
        V.push_back(j);
      }
      if (V.size() >= k) break;
    }
    if (V.size() < k) {
      puts("-1");
      continue;
    }
    printf("%d\n", sum);
    for (int i = 0; i < V.size(); i++) Save[V[i]] = t + d - 1;
  }
  return 0;
}
