#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, q;
  cin >> n >> q;
  vector<long long> serv(n + 1);
  while (q--) {
    long long t, k, d, ans = -1;
    cin >> t >> k >> d;
    vector<long long> res;
    for (long long i = 1; i <= n && k > 0; i++)
      if (t >= serv[i]) res.push_back(i), k--;
    if (!k) {
      ans = 0;
      for (auto e : res) serv[e] = t + d, ans += e;
    }
    cout << ans << "\n";
  }
  return 0;
}
