#include <bits/stdc++.h>
int main() {
  int N, Q;
  scanf("%d%d", &N, &Q);
  int et[N + 1];
  memset(et, -1, sizeof(et));
  while (Q-- > 0) {
    int t, k, d;
    scanf("%d%d%d", &t, &k, &d);
    int ans = -1;
    int as = 0;
    for (int i = 1; i <= N; i++) {
      if (t > et[i]) et[i] = -1;
      if (et[i] == -1) as++;
    }
    if (as >= k) {
      ans = 0;
      for (int i = 1; i <= N && k > 0; i++) {
        if (et[i] == -1) {
          ans += i;
          k--;
          et[i] = t + d - 1;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
