#include <bits/stdc++.h>
using namespace std;
int server[105];
int main() {
  int n, q, t, k, d;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    server[i] = 1;
  }
  for (int i = 0; i < q; i++) {
    cin >> t >> k >> d;
    int c = 0, sum = 0;
    for (int i = 1; i <= n; i++) {
      if (server[i] <= t) {
        c++;
      }
    }
    if (c >= k) {
      c = k;
      for (int i = 1; i <= n; i++) {
        if (server[i] <= t) {
          sum += i;
          server[i] = t + d;
          c--;
        }
        if (c == 0) break;
      }
    } else {
      sum = -1;
    }
    printf("%d\n", sum);
  }
  return 0;
}
