#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int mod = 1000000007;
const double pi = acos(-1);
const long long OO = INT_MAX;
double distance(double a, double b, double x, double y) {
  return sqrt((x - a) * (x - a) + ((y - b) * (y - b)));
}
map<int, bool> u;
int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  int c[n];
  for (int i = 0; i < n; i++) c[i] = 0;
  while (q--) {
    int t, k, d;
    cin >> t >> k >> d;
    int m = 0;
    int ans = 0;
    int tc[n];
    for (int i = 0; i < n; i++) {
      tc[i] = c[i];
    }
    for (int i = 0; i < n; i++) {
      if (m == k) break;
      if (c[i] < t) {
        m++;
        tc[i] = t + (d - 1);
        ans += i + 1;
      }
    }
    if (m == k) {
      for (int i = 0; i < n; i++) c[i] = tc[i];
    }
    cout << (m == k ? ans : -1) << '\n';
  }
}
