#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, test;
  cin >> n >> test;
  map<long long int, long long int> arr;
  for (long long int i = 1; i <= n; i++) arr[i] = 0;
  while (test--) {
    long long int t, k, d;
    cin >> t >> k >> d;
    long long int count = 0, sum = 0;
    map<long long int, long long int> mp = arr;
    for (long long int i = 1; i <= n; i++) {
      if (mp[i] < t) {
        mp[i] = t + d - 1;
        sum += i;
        count++;
      }
      if (count == k) break;
    }
    if (count != k)
      cout << "-1\n";
    else {
      cout << sum << "\n";
      arr = mp;
    }
  }
}
