#include <bits/stdc++.h>
using namespace std;
int const N = 1e2 + 10;
int n, q, T[N];
int main() {
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int t, k, d;
    cin >> t >> k >> d;
    vector<int> used;
    int sum = 0;
    for (int j = 1; j <= n; j++)
      if (T[j] <= t) {
        used.push_back(j);
        if (used.size() == k) break;
      }
    if (used.size() != k) {
      cout << "-1\n";
      continue;
    }
    for (int j = 0; j < used.size(); j++) {
      int id = used[j];
      sum += id;
      T[id] = t + d;
    }
    cout << sum << '\n';
  }
  return 0;
}
