#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> t(q), k(q), d(q), ans(q, 0);
  map<int, int> m;
  for (int i = 0; i < q; i++) cin >> t[i] >> k[i] >> d[i];
  for (int i = 0; i < q; i++) {
    if (i == 0) {
      for (int j = 0; j < k[i]; j++) m[j + 1] = d[i];
      ans[i] = (k[i] * (k[i] + 1)) / 2;
      continue;
    }
    for (int j = 1; j <= n; j++) {
      m[j] -= (t[i] - t[i - 1]);
      if (m[j] <= 0) m.erase(j);
    }
    if (n - m.size() < k[i]) {
      ans[i] = -1;
    } else {
      for (int j = 1; j <= n && k[i]; j++) {
        if (m[j] <= 0) {
          m[j] = d[i];
          k[i]--;
          ans[i] += j;
        }
      }
    }
    for (int j = 1; j <= n; j++)
      if (m[j] <= 0) m.erase(j);
  }
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
  return 0;
}
