#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int ff = 0x3f3f3f3f;
int n, q;
int num[520];
int ans[maxn];
int main() {
  cin >> n >> q;
  for (int i = 1; i <= q; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int x[102];
    int cnt = 0;
    int j;
    for (j = 1; j <= n; j++) {
      if (num[j] <= a) {
        x[++cnt] = j;
        if (cnt == b) break;
      }
    }
    if (j == n + 1) {
      ans[i] = -1;
      continue;
    }
    for (j = 1; j <= cnt; j++) {
      num[x[j]] = a + c;
      ans[i] += x[j];
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
