#include <bits/stdc++.h>
using namespace std;
int WhenFree[302];
int main() {
  int N = 0, q = 0;
  scanf("%i%i", &N, &q);
  int cur_uses = 0;
  while (q--) {
    int T = 0, Uses = 0, HowLong = 0;
    scanf("%i%i%i", &T, &Uses, &HowLong);
    int DNW = Uses, answer_to = 0;
    for (int i = 1; i <= N; i++) {
      if (DNW) {
        if (!WhenFree[i]) {
          DNW--;
          answer_to += i;
        } else if (WhenFree[i] <= T) {
          WhenFree[i] = 0;
          DNW--;
          answer_to += i;
          cur_uses--;
        }
      } else
        break;
    }
    if (N - cur_uses < Uses)
      printf("-1\n");
    else {
      printf("%i\n", answer_to);
      answer_to = Uses;
      int cur = 1;
      while (answer_to) {
        if (WhenFree[cur] == 0) {
          answer_to--;
          WhenFree[cur] = T + HowLong;
          cur_uses++;
        }
        cur++;
      }
    }
  }
  return 0;
}
