#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
  int n, q, t, k, d, i, c, ans;
  cin >> n >> q;
  while (q--) {
    c = 0;
    ans = 0;
    cin >> t >> k >> d;
    for (i = 1; i <= n; i++) {
      if (a[i] <= t) {
        ans += i;
        c++;
      }
      if (c >= k) break;
    }
    if (c < k)
      cout << "-1\n";
    else {
      cout << ans << endl;
      c = 0;
      for (i = 1; i <= n; i++) {
        if (a[i] <= t) {
          a[i] = t + d;
          c++;
          if (c >= k) break;
        }
      }
    }
  }
  return 0;
}
