#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int q;
  cin >> q;
  long long a[n];
  memset(a, 0, sizeof a);
  while (q--) {
    int t, k, d;
    cin >> t >> k >> d;
    int count = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] <= t) {
        count++;
      }
    }
    if (count < k)
      cout << -1 << endl;
    else {
      long long ans = 0;
      count = 0;
      for (int i = 0; i < n && count < k; ++i) {
        if (a[i] <= t) {
          ans += (i + 1);
          a[i] = t + d;
          count++;
        }
      }
      cout << ans << endl;
    }
  }
}
