#include <bits/stdc++.h>
using namespace std;
vector<int> computer(100, 0);
int n, q, free_computers;
long s;
int t, k, d;
void question() {
  cin >> t >> k >> d;
  free_computers = 0;
  for (int j = 0; j < n && free_computers < k; j++) {
    if (computer[j] <= t) free_computers++;
  }
  if (k > free_computers)
    cout << -1 << "\n";
  else {
    s = 0;
    for (int j = 0; j < n && k != 0; j++) {
      if (computer[j] <= t) {
        k--;
        computer[j] = d + t;
        s += j + 1;
      }
    }
    cout << s << "\n";
  }
}
int main() {
  cin >> n >> q;
  for (int i = 0; i < q; i++) question();
  return 0;
}
