#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
long long n, q, a[111], cnt = 0, t, k, d;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> t >> k >> d;
    int last = t + d - 1;
    cnt = k;
    for (int j = 0; j < n; j++) {
      if (cnt == 0) break;
      if (a[j] < t) {
        cnt--;
      }
    }
    if (cnt)
      cout << "-1\n";
    else {
      cnt = k;
      long long sum = 0;
      for (int j = 0; j < n; j++) {
        if (cnt == 0) break;
        if (a[j] < t) {
          a[j] = last;
          sum += j + 1;
          cnt--;
        }
      }
      cout << sum << '\n';
    }
  }
  return 0;
}
