#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, t, k, d, count, sum1, sum;
  cin >> n >> q;
  int a[n + 1], b[n];
  for (int i = 0; i <= n; i++) a[i] = 0;
  while (q--) {
    sum1 = 0;
    count = 0;
    cin >> t >> k >> d;
    sum = t + d;
    for (int i = 1; i <= n; i++) {
      if (a[i] <= t) {
        b[count] = i;
        count++;
      }
      if (count == k) break;
    }
    if (count < k)
      cout << -1 << "\n";
    else {
      for (int j = 0; j < k; j++) {
        a[b[j]] = sum;
        sum1 += b[j];
      }
      cout << sum1 << endl;
    }
  }
}
