#include <bits/stdc++.h>
const int N = 1e6 + 6e3;
std::vector<int> start[N], end[N], use[N];
bool workers[111];
int t[N], k[N], d[N];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < q; ++i) {
    std::cin >> t[i] >> k[i] >> d[i];
    start[t[i]].push_back(i);
    end[t[i] + d[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) workers[i] = true;
  int rem = n;
  for (int i = 1; i < N; ++i) {
    for (auto x : end[i])
      for (auto y : use[x]) {
        workers[y] = true;
        ++rem;
      }
    for (auto x : start[i]) {
      if (rem < k[x]) continue;
      for (int j = 1; j <= n && k[x]; ++j)
        if (workers[j]) {
          use[x].push_back(j);
          --k[x];
          --rem;
          workers[j] = false;
        }
    }
  }
  for (int i = 0; i < q; ++i) {
    if (use[i].size() > 0u) {
      int sum = 0;
      for (auto x : use[i]) sum += x;
      std::cout << sum << std::endl;
    } else {
      std::cout << -1 << std::endl;
    }
  }
}
