#include <bits/stdc++.h>
using namespace std;
long long int n, q, a[105];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  while (q--) {
    long long int t, k, d;
    cin >> t >> k >> d;
    long long int ans = 0, ct = 0;
    for (long long int i = 1; i <= n; ++i)
      if (a[i] <= t) ct++;
    if (ct < k) {
      cout << -1 << endl;
      continue;
    }
    long long int st = 1, x = 0;
    while (st <= n) {
      if (a[st] > t) {
        st++;
        continue;
      }
      x++;
      a[st] = t + d;
      ans += st;
      if (x == k) break;
      st++;
    }
    cout << ans << endl;
  }
}
