#include <bits/stdc++.h>
using namespace std;
const long long LINF = 334ll << 53;
const int INF = 15 << 26;
const long long MOD = 1E9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> t(n), s(n), d(n);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      used;
  priority_queue<int, vector<int>, greater<int>> aval;
  for (int(i) = 0; (i) < (n); ++(i)) aval.push(i + 1);
  for (int(i) = 0; (i) < (q); ++(i)) {
    int now, s, t, ans = 0;
    cin >> now >> s >> t;
    while (!used.empty()) {
      if (used.top().first > now) break;
      aval.push(used.top().second);
      used.pop();
    }
    if (aval.size() < s) {
      cout << -1 << endl;
    } else {
      for (int(j) = 0; (j) < (s); ++(j)) {
        ans += aval.top();
        used.push(make_pair(now + t, aval.top()));
        aval.pop();
      }
      cout << ans << endl;
    }
  }
  return 0;
}
