#include <bits/stdc++.h>
using namespace std;
struct E {
  int tm;
  int id;
  int tag;
  E() {}
  E(int a, int b, int c) : tm(a), id(b), tag(c) {}
};
struct ECmp {
  ECmp() {}
  bool operator()(const E &a, const E &b) {
    if (a.tm != b.tm)
      return a.tm > b.tm;
    else
      return a.tag < b.tag;
  }
};
vector<int> ans[100005];
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> start(q), cost(q), tm(q);
  priority_queue<E, vector<E>, ECmp> events;
  for (int i = 0; i < q; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    start[i] = a;
    cost[i] = b;
    tm[i] = c;
    events.push(E(a, i, -1));
  }
  set<int> servers;
  for (int i = 1; i <= n; i++) servers.insert(i);
  while (events.size() > 0) {
    E e = events.top();
    events.pop();
    if (e.tag < 0) {
      if (servers.size() < cost[e.id])
        cout << -1 << endl;
      else {
        events.push(E(e.tm + tm[e.id], e.id, 1));
        int sum = 0;
        for (int k = 0; k < cost[e.id]; k++) {
          int x = *servers.begin();
          servers.erase(servers.begin());
          sum += x;
          ans[e.id].push_back(x);
        }
        cout << sum << endl;
      }
    } else {
      for (int i = 0; i < ans[e.id].size(); i++) servers.insert(ans[e.id][i]);
    }
  }
  return 0;
}
