#include <bits/stdc++.h>
using namespace std;
int n, q, ma[104], usin[104], x;
int main() {
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int t, k, d;
    cin >> t >> k >> d;
    x = 0;
    for (int i = 0; i < n; i++)
      if (ma[i] <= t) usin[x++] = i;
    if (x < k)
      cout << -1 << endl;
    else {
      int sum = 0;
      for (int i = 0; i < k; i++) ma[usin[i]] = t + d, sum += usin[i] + 1;
      cout << sum << endl;
    }
  }
}
