#include <bits/stdc++.h>
using namespace std;
int n, q;
int tim[10000];
int main() {
  while (~scanf("%d%d", &n, &q)) {
    memset(tim, -1, sizeof(tim));
    while (q--) {
      int ti, ni, di;
      scanf("%d%d%d", &ti, &ni, &di);
      int cnt = 0;
      for (int i = 1; i <= n; i++) {
        if (tim[i] <= ti) tim[i] = -1;
      }
      for (int i = 1; i <= n; i++) {
        if (tim[i] == -1) cnt++;
      }
      if (cnt >= ni) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
          if (tim[i] == -1) {
            if (ni > 0) {
              tim[i] = ti + di;
              sum += i;
              ni--;
            }
          }
        }
        printf("%d\n", sum);
      } else {
        printf("-1\n");
      }
    }
  }
}
