#include <bits/stdc++.h>
const int maxn = 1e5 + 5;
int t[maxn], k[maxn], d[maxn], sum[maxn];
int vis[105];
int main() {
  int n, q;
  while (scanf("%d%d", &n, &q) != EOF) {
    memset(vis, -1, sizeof(vis));
    memset(sum, 0, sizeof(sum));
    for (int i = 0; i < q; ++i) scanf("%d%d%d", &t[i], &k[i], &d[i]);
    for (int i = 0; i < q; ++i) {
      int cnt = 0;
      for (int j = 0; j < n; ++j)
        if (vis[j] == -1 || d[vis[j]] + t[vis[j]] <= t[i]) ++cnt;
      if (cnt < k[i]) {
        sum[i] = -1;
        continue;
      }
      int c1 = 0;
      for (int j = 0; j < n && c1 < k[i]; ++j)
        if (vis[j] == -1 || d[vis[j]] + t[vis[j]] <= t[i]) {
          sum[i] += j + 1;
          vis[j] = i;
          ++c1;
        }
    }
    for (int i = 0; i < q; ++i) printf("%d\n", sum[i]);
  }
  return 0;
}
