#include <bits/stdc++.h>
using namespace std;
int servers[105];
map<long long, pair<int, int> > x;
long long ans[1000005];
int main() {
  long long ser_num, tasks;
  cin >> ser_num >> tasks;
  long long t, k, d;
  for (long long i = 0; i < tasks; i++) {
    cin >> t >> k >> d;
    pair<int, int> y;
    y.first = k;
    y.second = d;
    x[t] = y;
  }
  bool flag = false;
  int available = 0;
  for (map<long long, pair<int, int> >::iterator i = x.begin(); i != x.end();
       i++) {
    for (int j = 0; j < ser_num; j++) {
      if (servers[j] != 0) {
        if (i->first >= servers[j] + x[servers[j]].second) {
          available++;
        }
      } else {
        available++;
      }
    }
    if (available >= (i->second).first) {
      available = (i->second).first;
      for (int j = 0; j < ser_num; j++) {
        if (servers[j] != 0) {
          if (i->first >= servers[j] + x[servers[j]].second) {
            servers[j] = i->first;
            available--;
            ans[i->first] += (j + 1);
          }
        } else {
          servers[j] = i->first;
          available--;
          ans[i->first] += (j + 1);
        }
        if (available == 0) {
          cout << ans[i->first] << " " << endl;
          break;
        }
      }
    } else {
      cout << -1 << " " << endl;
    }
    available = 0;
  }
  cout << endl;
  return 0;
}
