#include <bits/stdc++.h>
using namespace std;
unordered_map<char, long long> m;
vector<char> v;
long long n, q, t, d, k, x, f[10000], s[10000], i;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> q;
  while (q--) {
    cin >> t >> k >> d;
    x = 0;
    for (i = 0; i < n; i++)
      if (f[i] <= t) s[x++] = i;
    if (x < k)
      cout << -1 << endl;
    else {
      long long sum = 0;
      for (i = 0; i < k; i++) {
        f[s[i]] = t + d;
        sum += s[i] + 1;
      }
      cout << sum << endl;
    }
  }
}
