#include <bits/stdc++.h>
using namespace std;
struct job {
  int t, k, d;
};
bool jobCompare(const job& a, const job& b) { return a.t < b.t; }
struct event {
  int t;
  vector<int> servants;
};
bool eventCompare(const event& a, const event& b) { return a.t >= b.t; }
void processEvents(vector<event>& evs, int time, vector<bool>& servants) {
  if (!evs.size()) {
    return;
  }
  while (evs.back().t <= time) {
    auto e = evs.back();
    evs.pop_back();
    for (int i : e.servants) {
      servants[i] = true;
    }
    if (evs.size()) {
      std::pop_heap(evs.begin(), evs.end(), &eventCompare);
    } else {
      return;
    }
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  vector<job> jobs;
  jobs.resize(q);
  for (int i = 0; i < q; ++i) {
    cin >> jobs[i].t >> jobs[i].k >> jobs[i].d;
  }
  std::sort(jobs.begin(), jobs.end(), &jobCompare);
  vector<bool> servants;
  servants.resize(n);
  for (int i = 0; i < n; ++i) servants[i] = true;
  vector<event> events;
  for (int i = 0; i < q; ++i) {
    processEvents(events, jobs[i].t, servants);
    event cur;
    int sum = 0;
    cur.t = jobs[i].t + jobs[i].d;
    for (int j = 0; j < n && cur.servants.size() < jobs[i].k; ++j) {
      if (servants[j]) {
        servants[j] = false;
        sum += j + 1;
        cur.servants.push_back(j);
      }
    }
    if (cur.servants.size() < jobs[i].k) {
      cout << -1 << endl;
      for (int j : cur.servants) {
        servants[j] = true;
      }
    } else {
      cout << sum << endl;
      if (events.size())
        std::push_heap(events.begin(), events.end(), &eventCompare);
      events.push_back(cur);
      std::push_heap(events.begin(), events.end(), &eventCompare);
      std::pop_heap(events.begin(), events.end(), &eventCompare);
    }
  }
  return 0;
}
