#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  long long servers, tasks;
  cin >> servers >> tasks;
  vector<long long> v(servers + 5);
  long long cur = servers;
  for (long long i = (long long)1; i <= (long long)tasks; i++) {
    long long start, need, time;
    cin >> start >> need >> time;
    for (long long i = (long long)1; i <= (long long)servers; i++) {
      if (v[i] < start && v[i] != 0) {
        v[i] = 0;
        cur++;
      }
    }
    if (cur < need)
      cout << -1 << endl;
    else {
      long long sum = 0, i = 1;
      while (need) {
        if (v[i] == 0) {
          v[i] = start + time - 1;
          cur--;
          need--;
          sum += i;
        }
        i++;
      }
      cout << sum << endl;
    }
  }
  return 0;
}
