#include <bits/stdc++.h>
using namespace std;
long long a[105], b[105], n, q, t, k, d, m;
int main() {
  ;
  ;
  ;
  ;
  ;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> t >> k >> d;
    m = 0;
    for (int j = 0; j < n; j++)
      if (a[j] <= t) b[m++] = j;
    if (m < k)
      cout << -1 << endl;
    else {
      int s = 0;
      for (int j = 0; j < k; j++) a[b[j]] = t + d, s += b[j] + 1;
      cout << s << endl;
    }
  }
  return 0;
}
