#include <bits/stdc++.h>
using namespace std;
int arr[500500];
int freex[500500];
void dec(int t) {
  for (int w = 1; w <= 100; w++) {
    freex[w] = max(0, freex[w] - t);
  }
}
int main() {
  int a, b, c;
  scanf("%d%d", &a, &b);
  int atm = 0;
  for (int w = 0; w < b; w++) {
    int foo[3];
    scanf("%d%d%d", foo, foo + 1, foo + 2);
    int t = foo[0] - atm;
    atm = foo[0];
    dec(t);
    int cnt = 0;
    int idx = 0;
    int flag = 0;
    for (int x = 1; x <= a; x++) {
      if (cnt == foo[1]) break;
      if (!freex[x]) {
        cnt++;
      }
    }
    if (cnt < foo[1]) {
      printf("-1\n");
    } else {
      int answ = 0;
      for (int x = 1; x <= a && cnt; x++) {
        if (!freex[x]) {
          freex[x] = foo[2];
          answ += x;
          cnt--;
        }
      }
      printf("%d\n", answ);
    }
  }
}
