#include <bits/stdc++.h>
using namespace std;
int ans[100005];
int busy[105];
bool cmp(pair<int, pair<int, int> > &a, pair<int, pair<int, int> > &b) {
  if (a.second.first != b.second.first) return a.second.first < b.second.first;
  return a.second.second < b.second.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(30);
  int n, q;
  cin >> n >> q;
  memset(busy, 0, sizeof(busy));
  vector<pair<int, pair<int, int> > > arr;
  for (int i = 1; i <= q; i++) {
    int t, k, d;
    cin >> t >> k >> d;
    arr.push_back({i, {t, k}});
    arr.push_back({i, {t + d, -k}});
    ans[i] = -1;
  }
  int cnt = n;
  sort(arr.begin(), arr.end(), cmp);
  for (auto x : arr) {
    if (x.second.second < 0) {
      for (int i = 1; i <= n; i++) {
        if (busy[i] == x.first) {
          busy[i] = 0;
          cnt++;
        }
      }
    } else if (x.second.second <= cnt) {
      long long tmp = 0;
      for (int i = 1, j = x.second.second; i <= n && j > 0; i++) {
        if (busy[i] == 0) {
          busy[i] = x.first;
          tmp += i;
          j--;
        }
      }
      cnt -= x.second.second;
      ans[x.first] = tmp;
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] << endl;
  }
}
