#include <bits/stdc++.h>
using namespace std;
int server[200];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int s, q, cnt = 0;
  cin >> s >> q;
  int t = 0, k = 0, d = 0;
  int re;
  vector<int> v;
  for (int i = 0; i < q; i++) {
    cin >> t >> k >> d;
    re = 0;
    cnt = 0;
    for (int i = 0; i < s; i++) {
      if (t > server[i]) {
        cnt++;
      }
      if (cnt == k) break;
    }
    if (cnt != k) {
      cout << -1 << endl;
      continue;
    }
    cnt = 0;
    for (int i = 0; i < s && cnt != k; i++) {
      if (t > server[i]) {
        cnt++;
        server[i] = t + d - 1;
        re += i + 1;
      }
    }
    cout << re << endl;
  }
  return 0;
}
