#include <bits/stdc++.h>
using namespace std;
int n, q, t, k, d, res, a[102], r;
int main() {
  cin >> n >> q;
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &t, &k, &d);
    res = 0;
    r = 0;
    for (int j = 1; j <= n; j++)
      if (a[j] < t) r++;
    if (r >= k) {
      for (int j = 1; j <= n; j++)
        if (a[j] < t) {
          k--;
          a[j] = t + d - 1;
          res += j;
          if (k == 0) break;
        }
      printf("%d\n", res);
    } else
      printf("%d\n", -1);
  }
  return 0;
}
