#include <bits/stdc++.h>
int main() {
  int n, q;
  std::cin >> n >> q;
  int ans[q], servers[n], server;
  for (server = 0; server < n; ++server) {
    servers[server] = 0;
  }
  int index, t, k, d, planner[n];
  for (int i = 0; i < q; ++i) {
    server = 0;
    index = 0;
    std::cin >> t >> k >> d;
    while (index < k && server < n) {
      if (servers[server] <= t) {
        planner[index++] = server;
        servers[server] = t;
      }
      ++server;
    }
    if (index == k) {
      ans[i] = k;
      for (index = 0; index < k; ++index) {
        ans[i] += planner[index];
        servers[planner[index]] += d;
      }
    } else {
      ans[i] = -1;
    }
  }
  for (int a : ans) {
    std::cout << a << std::endl;
  }
  return 0;
}
