#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000, 102400000")
#pragma GCC optimize("O2")
using namespace std;
typedef struct edge {
  int dest, w;
  struct edge* next;
} edge;
typedef struct {
  int val;
  edge* adj;
} vertex;
typedef struct {
  vertex vexList[100];
  int v, e;
} Graph;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = 3.14159265358979323846;
const int maxn = 1e5 + 100;
typedef struct {
  int t, k, d;
} task;
task tsk[maxn];
int flag[maxn];
int n, q;
int main() {
  int i, j, free, sum;
  scanf("%d%d", &n, &q);
  for (i = 1; i <= q; ++i) scanf("%d%d%d", &tsk[i].t, &tsk[i].k, &tsk[i].d);
  for (i = 1; i <= q; ++i) {
    free = sum = 0;
    for (j = 1; j <= n; ++j)
      flag[j] - (tsk[i].t - tsk[i - 1].t) > 0
          ? flag[j] -= (tsk[i].t - tsk[i - 1].t)
          : flag[j] = 0;
    for (j = 1; j <= n && free < tsk[i].k; ++j)
      if (!flag[j]) free++;
    if (free < tsk[i].k) {
      printf("-1\n");
      continue;
    }
    free = 0;
    for (j = 1; j <= n && free < tsk[i].k; ++j)
      if (!flag[j]) free++, sum += j, flag[j] = tsk[i].d;
    printf("%d\n", sum);
  }
  return 0;
}
