#include <bits/stdc++.h>
using namespace std;
const int maxt = int(1e6) + 5;
vector<int> upd[maxt];
pair<int, int> Q[maxt];
int main(void) {
  int n, q, t, k, d;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", &t, &k, &d);
    Q[t] = {k, d};
  }
  set<int> mac;
  for (int i = 1; i <= n; i++) mac.insert(i);
  for (int i = 0; i < maxt; i++) {
    for (auto it : upd[i]) mac.insert(it);
    if (Q[i].first) {
      if (Q[i].first <= int(mac.size())) {
        int val = 0;
        while (Q[i].first--) {
          int top = *mac.begin();
          mac.erase(mac.begin());
          val += top;
          if (i + Q[i].second < maxt) upd[i + Q[i].second].push_back(top);
        }
        printf("%d\n", val);
      } else
        printf("-1\n");
    }
  }
}
