#include <bits/stdc++.h>
using namespace std;
vector<int> queries[2000001];
set<int> available;
set<int> store[2000001];
int ans[2000001], t[2000001], d[2000001], k[2000001];
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  int i, j, n, q, x, y, id, ctr;
  cin >> n >> q;
  for (i = 1; i <= q; i++) {
    cin >> t[i] >> k[i] >> d[i];
    queries[t[i]].push_back(i);
  }
  for (i = 1; i <= n; i++) available.insert(i);
  for (i = 1; i <= 1000000; i++) {
    for (auto it : store[i]) available.insert(it);
    store[i].clear();
    if (!queries[i].size()) continue;
    id = queries[i][0];
    if (available.size() < k[id]) {
      ans[id] = -1;
      continue;
    }
    ctr = 0;
    while (1) {
      if (ctr >= k[id]) break;
      x = *(available.begin());
      available.erase(x);
      ans[id] += x;
      store[i + d[id]].insert(x);
      ctr++;
    }
  }
  for (i = 1; i <= q; i++) cout << ans[i] << "\n";
  return 0;
}
