#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int fre[N];
int main() {
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  set<pair<int, vector<int> > > s;
  int cnt = n;
  while (q--) {
    int t, k, d;
    cin >> t >> k >> d;
    while (s.size() && s.begin()->first <= t) {
      for (int i : s.begin()->second) {
        fre[i] = 0;
        cnt++;
      }
      s.erase(s.begin());
    }
    if (cnt < k) {
      cout << "-1\n";
      continue;
    }
    vector<int> v;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      if (fre[i] == 0) {
        v.push_back(i);
        fre[i] = 1;
        sum += i;
        k--;
        cnt--;
      }
      if (k == 0) break;
    }
    cout << sum << "\n";
    s.insert(make_pair(t + d, v));
  }
  return 0;
}
