#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
int t, n;
int a[200];
int main() {
  int n, q, t, k, d;
  int cnt;
  int sum;
  memset(a, 0, sizeof a);
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cnt = 0;
    sum = 0;
    cin >> t >> k >> d;
    for (int j = 0; j < n; j++) {
      if (a[j] < t) cnt++;
    }
    if (cnt < k)
      cout << "-1" << endl;
    else {
      for (int j = 0; j < n; j++) {
        if (a[j] < t) {
          k--;
          a[j] = t + d - 1;
          sum += j + 1;
        }
        if (k == 0) break;
      }
      cout << sum << endl;
    }
  }
  return 0;
}
