#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> ser(n, 0), check;
  int i;
  for (i = 0; i < q; i++) {
    int in, nu, out, j, count = 0, sum;
    cin >> in >> nu >> out;
    check.clear();
    for (j = 0; j < n; j++) {
      if (in > ser[j]) {
        count++;
        check.push_back(j);
        if (count == nu) {
          break;
        }
      }
    }
    if (count < nu) {
      cout << -1 << endl;
      continue;
    } else {
      sum = 0;
      for (j = 0; j < check.size(); j++) {
        ser[check[j]] = in + out - 1;
        sum += check[j] + 1;
      }
      cout << sum << endl;
    }
  }
  return 0;
}
