#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, q, arr[103], t, k, d;
  memset(arr, 0, sizeof arr);
  cin >> n >> q;
  for (int i = 0; i < q; ++i) {
    cin >> t >> k >> d;
    int x1 = 0, x2 = 0;
    for (int j = 0; ((j < n) && (x1 < k)); ++j) x1 += (arr[j] < t);
    if (x1 < k) {
      cout << -1 << endl;
      continue;
    }
    for (int j = 0; ((j < n) && (x1 > 0)); ++j)
      if (arr[j] < t) x2 += (j + 1), --x1, arr[j] = t + d - 1;
    cout << x2 << endl;
  }
  return 0;
}
