#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
int ans[N];
vector<pair<pair<int, int>, pair<int, int> > > v;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, qq;
  cin >> n >> qq;
  for (int i = 1; i <= qq; i++) {
    int t, k, d;
    cin >> t >> k >> d;
    v.push_back({{t, i}, {k, d}});
  }
  set<pair<int, vector<int> > > q;
  sort(v.begin(), v.end());
  set<int> s;
  for (int i = 1; i <= n; i++) s.insert(i);
  for (auto server : v) {
    while (!q.empty() && q.begin()->first <= server.first.first) {
      auto fr = *q.begin();
      for (auto j : fr.second) s.insert(j);
      q.erase(q.begin());
    }
    if (s.size() < server.second.first)
      ans[server.first.second] = -1;
    else {
      int req = server.second.first;
      vector<int> temp;
      int sum = 0;
      while (req--) {
        int x = *s.begin();
        s.erase(s.begin());
        sum += x;
        temp.push_back(x);
      }
      ans[server.first.second] = sum;
      q.insert({server.first.first + server.second.second, temp});
    }
  }
  for (int i = 1; i <= qq; i++) cout << ans[i] << '\n';
  return 0;
}
