#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> avail(n, 0);
  int a, s, d;
  while (q-- > 0) {
    cin >> a >> s >> d;
    int count = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      if (avail.at(i) <= a) {
        count++;
      }
    }
    if (s <= count) {
      for (int i = 0; i < n && s; i++) {
        if (avail.at(i) <= a) {
          sum += (i + 1);
          avail[i] = d + a;
          s--;
        }
      }
      cout << sum << endl;
    } else
      cout << "-1" << endl;
  }
  return 0;
}
