#include <bits/stdc++.h>
using namespace std;
struct event {
  int time;
  int id;
  int type;
};
bool cmp_events(event& e1, event& e2) {
  if (e1.time == e2.time) {
    return e1.type < e2.type;
  } else {
    return e1.time < e2.time;
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  vector<event> events;
  int t, d, k;
  int ans[q + 1];
  int occ[n + 1];
  for (int i = 1; i <= n; ++i) {
    occ[i] = -1;
  }
  for (int i = 1; i <= q; ++i) {
    cin >> t >> k >> d;
    events.push_back(event{t, i, +k});
    events.push_back(event{t + d, i, -k});
    ans[i] = 0;
  }
  sort(events.begin(), events.end(), cmp_events);
  int numocc = 0;
  for (int i = 0; i < events.size(); ++i) {
    if (events[i].type > 0) {
      if (events[i].type + numocc <= n) {
        ans[events[i].id] = 0;
        for (int j = 1, count = events[i].type; j <= n and count > 0; ++j) {
          if (occ[j] == -1) {
            occ[j] = events[i].id;
            ans[events[i].id] += j;
            count -= 1;
          }
        }
        numocc += events[i].type;
      } else {
        ans[events[i].id] = -1;
      }
    } else {
      if (ans[events[i].id] != -1) {
        for (int j = 1, count = -events[i].type; j <= n and count > 0; ++j) {
          if (occ[j] == events[i].id) {
            occ[j] = -1;
            count -= 1;
          }
        }
        numocc += events[i].type;
      }
    }
  }
  for (int i = 1; i <= q; ++i) {
    cout << ans[i] << "\n";
  }
}
