#include <bits/stdc++.h>
using namespace std;
const int SZ = 1010;
const long long INF = 1000000010;
const long long mod = 1000000007;
const double eps = 1e-8;
long long read() {
  long long n = 0;
  char a = getchar();
  int flag = 0;
  while (a < '0' || a > '9') {
    if (a == '-') flag = 1;
    a = getchar();
  }
  while (a >= '0' && a <= '9') n = n * 10 + a - '0', a = getchar();
  if (flag) n = -n;
  return n;
}
bool use[110];
int r[110];
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int t = read(), k = read(), d = read();
    for (int j = 1; j <= n; j++)
      if (r[j] < t) use[j] = 0;
    int tot = 0;
    for (int j = 1; j <= n; j++)
      if (!use[j]) tot++;
    if (tot < k) {
      puts("-1");
      continue;
    }
    tot = 0;
    int ans = 0;
    for (int j = 1; j <= n; j++)
      if (!use[j] && ++tot <= k) use[j] = 1, ans += j, r[j] = t + d - 1;
    printf("%d\n", ans);
  }
  return 0;
}
