#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 1e3 + 10;
const long long MOD = 1e9 + 7;
int cases = 0;
using std::string;
const int dir[][2] = {{-1, 0}, {-1, -1}, {-1, 1}, {0, -1},
                      {0, 1},  {1, -1},  {1, 0},  {1, 1}};
int next[MAXN];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int t, k, d;
    std::vector<int> tmp;
    scanf("%d%d%d", &t, &k, &d);
    int cnt = 0;
    int res = 0;
    for (int i = 1; i <= n; ++i) {
      if (next[i] <= t) {
        tmp.push_back(i);
      }
      if (tmp.size() == k) {
        for (int u : tmp) {
          next[u] = t + d;
          res += u;
        }
        break;
      }
    }
    printf("%d\n", res == 0 ? -1 : res);
  }
  return 0;
}
