#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4786)
using namespace std;
string to_string(long long x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
long long to_int(const string &s) {
  stringstream ss;
  ss << s;
  long long x;
  ss >> x;
  return x;
}
vector<pair<int, int> > vs;
int n;
int comp(pair<int, int> p1, pair<int, int> p2) {
  if (p2.second == p1.second) {
    return p1.first < p2.first;
  } else if (p1.second < p2.second) {
    return true;
  } else
    return false;
}
int main(void) {
  int q, i, j, k;
  while (cin >> n >> q) {
    vs.clear();
    for (i = 0; i < n; i++) {
      vs.push_back(make_pair(i + 1, -1));
    }
    int ti, ki, di;
    for (i = 0; i < q; i++) {
      scanf("%d %d %d", &ti, &ki, &di);
      int sum = 0;
      int cnt = 0;
      vector<int> ids;
      for (j = 0; j < n; j++) {
        if (ti >= vs[j].second) {
          sum += vs[j].first;
          ids.push_back(j);
          cnt++;
        }
        if (cnt == ki) {
          break;
        }
      }
      int sz = ids.size();
      if (cnt == ki) {
        cout << sum << endl;
        for (j = 0; j < sz; j++) {
          vs[ids[j]].second = ti + di;
        }
      } else {
        cout << -1 << endl;
      }
    }
  }
  return 0;
}
