#include <bits/stdc++.h>
using namespace std;
int main() {
  int numSer, numTask;
  int taskBegin[100000], taskSer[100000], taskEnd[100000], sum[100000];
  int serState[100];
  long long serEnd[100];
  int freeSer;
  for (int p = 0; p < 100; p++) {
    serState[p] = -1;
    serEnd[p] = 10000000;
  }
  int temp = 0;
  cin >> numSer >> numTask;
  freeSer = numSer;
  for (int q = 0; q < numTask; q++) {
    cin >> taskBegin[q] >> taskSer[q] >> temp;
    taskEnd[q] = temp + taskBegin[q];
    sum[q] = 0;
  }
  temp = 0;
  for (int i = 0; i < numTask; i++) {
    for (int h = 0; h < numSer; h++) {
      if (serEnd[h] <= taskBegin[i]) {
        serEnd[h] = 10000000;
        freeSer++;
        serState[h] = -1;
      }
    }
    if (freeSer < taskSer[i]) {
      sum[i] = -1;
      temp = 0;
      continue;
    }
    temp = taskSer[i];
    for (int j = 0; j < numSer; j++) {
      if (serState[j] == -1) {
        sum[i] = sum[i] + j + 1;
        temp--;
        serState[j] = i;
        freeSer--;
        serEnd[j] = taskEnd[i];
      }
      if (temp == 0) break;
    }
  }
  for (int b = 0; b < numTask; b++) cout << sum[b] << endl;
  return 0;
}
