#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  set<int> st;
  for (int i = 0; i < (n); ++i) st.insert(i + 1);
  vector<vector<pair<pair<int, int>, int>>> query(1000005);
  vector<vector<int>> recover(1001005);
  for (int i = 0; i < (q); ++i) {
    int t, k, d;
    cin >> t >> k >> d;
    query[t].push_back(pair<pair<int, int>, int>(pair<int, int>(k, d), i));
  }
  vector<int> ans(q, -1);
  for (int ti = 0; ti < (1000005); ++ti) {
    for (auto e : recover[ti]) {
      st.insert(e);
    }
    for (int i = 0; i < (query[ti].size()); ++i) {
      int k = query[ti][i].first.first;
      int d = query[ti][i].first.second;
      int id = query[ti][i].second;
      if (st.size() < k) {
        ans[id] = -1;
        continue;
      }
      int sum = 0;
      for (int j = 0; j < (k); ++j) {
        sum += *st.begin();
        recover[ti + d].push_back(*st.begin());
        st.erase(st.begin());
      }
      ans[id] = sum;
    }
  }
  for (int qi = 0; qi < (q); ++qi) cout << ans[qi] << endl;
  return 0;
}
