#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n = 0, q = 0;
  cin >> n >> q;
  vector<long> s(n);
  int free = 0;
  for (int i = 0; i < q; i++) {
    long t = 0;
    int k = 0, d = 0;
    cin >> t >> k >> d;
    free = 0;
    for (int i = 0; i < n; i++)
      if (s[i] < t) {
        s[i] = 0;
        free++;
      }
    if (free >= k) {
      long sum = 0;
      for (int i = 0; i < n; i++) {
        if (k && s[i] == 0) {
          s[i] = t + d - 1;
          free--;
          sum += i + 1;
          k--;
        }
      }
      cout << sum << endl;
    } else {
      cout << "-1" << endl;
    }
  }
}
