#include <bits/stdc++.h>
using namespace std;
int n, m, ti[500005], b[500005];
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int t, k, d;
    scanf("%d%d%d", &t, &k, &d);
    int h = 0, ans = 0, cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (ti[i] <= t) {
        b[++h] = i;
        cnt++;
        if (cnt == k) break;
      }
    }
    if (cnt == k) {
      for (int i = 1; i <= h; i++) {
        ti[b[i]] = t + d;
        ans += b[i];
      }
      printf("%d\n", ans);
    } else
      puts("-1");
  }
  return 0;
}
