#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin.tie(NULL);
  long long int n, m, i, j, k, ans = 0, d, t, q;
  cin >> n >> q;
  long long int tc[n + 1];
  long long int tp = 0, dp = 0, ip = 0, kp = 0, oc = 0, ct = 0;
  for (i = 0; i <= n; i++) tc[i] = -1;
  while (q--) {
    cin >> t >> k >> d;
    long long int cnt = 0;
    ans = 0, ct = t;
    for (i = 0; i < n; i++) {
      if (tc[i] < ct) cnt++;
    }
    if (cnt >= k) {
      for (i = 0; i < n && k > 0; i++) {
        if (tc[i] < ct) k--, tc[i] = d + ct - 1, ans += i + 1;
      }
      cout << ans << "\n";
    } else
      cout << -1 << "\n";
  }
  return 0;
}
