#include <bits/stdc++.h>
using namespace std;
set<int> sett;
int q[100010][3];
int rem[110];
int main(int argc, char const *argv[]) {
  int n, qq, t, k, d;
  cin >> n >> qq;
  for (int i = 0; i < qq; ++i) {
    cin >> q[i][0] >> q[i][1];
    cin >> q[i][2];
  }
  for (int i = 0; i < qq; i++) {
    int a = q[i][0];
    int b = q[i][1];
    int c = q[i][2];
    int x, s;
    x = s = 0;
    for (int j = 1; j <= n; j++) {
      if (x == b) break;
      if (rem[j] <= a) {
        x++;
        s += j;
      }
    }
    if (x != b) {
      cout << "-1\n";
      continue;
    } else {
      cout << s << "\n";
      int done = 0;
      int ptr = 1;
      while (done != x) {
        if (rem[ptr] <= a) {
          rem[ptr] = a + c;
          done++;
        }
        ptr++;
      }
    }
  }
  return 0;
}
