#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, que, arr[110], k, d, t, siz = 1, available, total, temp;
  cin >> n >> que;
  memset(arr, 0, sizeof(arr));
  while (que--) {
    total = available = 0;
    cin >> t >> k >> d;
    temp = k;
    for (int i = 1; i <= n; i++) {
      if (t > arr[i]) available++;
    }
    if (available < k) cout << "-1" << endl;
    if (available >= k) {
      for (int i = 1; i <= n; i++)
        if (temp > 0 && t > arr[i]) total += i, temp--, arr[i] = (d + t - 1);
    }
    if (temp == 0) cout << total << endl;
  }
  return 0;
}
