#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  int free[n + 1];
  for (int i = 1; i <= n; i++) {
    free[i] = 0;
  }
  for (int i = 1; i <= q; i++) {
    int t, s, d;
    cin >> t >> s >> d;
    int total = 0;
    for (int j = 1; j <= n; j++) {
      if (free[j] <= t) {
        total++;
      }
    }
    if (total < s) {
      cout << "-1" << endl;
    } else {
      int sum = 0;
      for (int j = 1; j <= n; j++) {
        if (free[j] <= t && s != 0) {
          sum += j;
          free[j] = t + d;
          s--;
        }
      }
      cout << sum << endl;
    }
  }
  return 0;
}
