#include <bits/stdc++.h>
using namespace std;
int a[101];
int main() {
  int n, q, t, k, d, g = 0, f = 0;
  cin >> n >> q;
  while (q--) {
    g = 0;
    cin >> t >> k >> d;
    for (int i = 1; i <= n; i++) {
      if (a[i] <= t) {
        g++;
      }
    }
    if (g >= k) {
      f = 0;
      for (int i = 1; i <= n; i++) {
        if (a[i] <= t && k > 0) {
          a[i] = t + d;
          f += i;
          k--;
        }
      }
      cout << f << endl;
    } else {
      cout << -1 << endl;
    }
  }
}
