#include <bits/stdc++.h>
using namespace std;
long long v[200];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  while (q--) {
    long long t, k, d, cnt = 0;
    cin >> t >> k >> d;
    for (long long i = 1; i <= n; ++i) {
      if (t >= v[i]) ++cnt;
      if (cnt == k) break;
    }
    if (cnt == k) {
      long long ans = 0;
      cnt = 0;
      for (int i = 1; i <= n; ++i) {
        if (t >= v[i]) {
          ans += i;
          v[i] = d + t;
          ++cnt;
        }
        if (cnt == k) break;
      }
      cout << ans << '\n';
    } else
      cout << -1 << '\n';
  }
  return 0;
}
