#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 100;
int t[maxn], k[maxn], d[maxn];
struct node {
  int id, t;
  friend bool operator<(node aa, node bb) { return aa.t > bb.t; }
};
int main() {
  int n, q;
  while (~scanf("%d%d", &n, &q)) {
    int i;
    for (i = 1; i <= q; i++) {
      scanf("%d%d%d", &t[i], &k[i], &d[i]);
    }
    priority_queue<int, vector<int>, greater<int> > ID;
    priority_queue<node> T;
    while (!ID.empty()) {
      ID.pop();
    }
    while (!T.empty()) {
      T.pop();
    }
    for (i = 1; i <= n; i++) {
      ID.push(i);
    }
    for (i = 1; i <= q; i++) {
      while (!T.empty()) {
        node now = T.top();
        if (t[i] >= now.t) {
          ID.push(now.id);
          T.pop();
        } else {
          break;
        }
      }
      if (ID.size() < k[i]) {
        printf("-1\n");
      } else {
        int j, ans = 0;
        for (j = 1; j <= k[i]; j++) {
          node now;
          now.id = ID.top();
          now.t = t[i] + d[i];
          T.push(now);
          ID.pop();
          ans += now.id;
        }
        printf("%d\n", ans);
      }
    }
  }
}
