100 1
1000000 100 1000
 5 3
1 4 10
2 2 5
3 1 6
 10 4
1 5 20
2 5 200
100 6 20
101 1 100
 5 3
1 3 4
4 3 4
6 4 1
 4 1
6 1 1
 8 6
1 3 20
4 2 1
6 6 5
9 1 1
15 3 6
21 8 8
 4 5
1 2 3
2 1 3
3 1 2
4 3 3
5 4 1
 8 4
1 3 2
2 3 100
10 6 20
11 5 20
 4 10
1 1 1
3 1 2
4 1 2
6 1 2
8 1 2
13 1 2
16 1 1
17 1 2
19 3 1
20 1 1
 5 3
1 4 4
4 2 2
5 5 2
 4 3
1 3 10
2 2 15
12 4 1
 5 4
1 1 4
2 4 4
5 2 20
11 5 2
 1 10
4 1 1
9 1 1
10 1 1
12 1 1
13 1 1
15 1 1
16 1 1
18 1 1
19 1 1
20 1 1

5050
 10
-1
5
 15
40
-1
1
 6
-1
10
 1
 6
9
-1
4
15
36
 3
3
4
-1
10
 6
15
-1
21
 1
1
2
1
1
1
1
1
6
1
 10
-1
15
 6
-1
10
 1
14
-1
15
 1
1
1
1
1
1
1
1
1
1

import java.io.*;
import java.util.*;

public class b {
	
	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner zizo = new Scanner(System.in);
		PrintWriter wr = new PrintWriter(System.out);
		
		int n = zizo.nextInt();
		int q = zizo.nextInt();
		boolean[]a = new boolean[n];
		int c = 0;
		PriorityQueue<pair> pq = new PriorityQueue<>();
		for(int i = 1;i <= q; i++) {
			int t = zizo.nextInt();
			int k = zizo.nextInt();
			int d = zizo.nextInt();
			d = t+d-1;
			//if(t == 5)System.out.println(pq.peek().d);
			while(!pq.isEmpty() && pq.peek().d < t) {
				a[pq.remove().k] = false;
				c--;
			}
//			if(t == 5) {
//				System.out.println(c+" "+Arrays.toString(a));
//			}
			if(n-c < k) {
				wr.println(-1);
				continue;
			}
			int sum = 0;
			int cur = 0;
			for(int j = 0;j < n && cur < k; j++) {
				if(!a[j]) {
					a[j] = true;
					pq.add(new pair(i,j,d));
					c++;
					cur++;
					sum+=j+1;
				}
			}
			wr.println(sum);
		}
		
		wr.close();
	}

	static long nCr(int n, int k)		
	{
		long ans = 1;
		
		for(int i = 1; i <= k; ++i)
			ans = (n - k + i) * ans / i;
		
		return ans;
	}
}
class pair implements Comparable<pair>{
	int i, k,d;
	pair(int a,int b,int c){i = a;k = b;d = c;}
	@Override
	public int compareTo(pair o) {
		// TODO Auto-generated method stub
		return d != o.d ? d-o.d : i - o.i;
	}
}
class DSU {
	int n,sets;
	int[]rank,parent,size;
	DSU(int n){
		sets = n;
		rank = new int[n];
		parent = new int[n];
		size = new int[n];
		for(int i = 0;i < n; i++) {
			size[i] = 1;
			parent[i] = i;
		}
	}
	
	int findSet(int i) {
		return parent[i] == i? i : (parent[i] = findSet(parent[i]));
	}
	
	boolean union(int u,int v) {
		int x = findSet(u);
		int y = findSet(v);
		if(x == y)
			return false;
		if(rank[x] < rank[y]) {
			size[y] += size[x];
			parent[x] = y;
		}
		else {
			size[x] += size[y];
			if(rank[x] == rank[y])
				rank[x]++;
			parent[y] = x;
		}
		sets--;
		return true;
	}
}

class Scanner 
{
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

	public String next() throws IOException 
	{
		while (st == null || !st.hasMoreTokens()) 
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {return Integer.parseInt(next());}

	public long nextLong() throws IOException {return Long.parseLong(next());}

	public String nextLine() throws IOException {return br.readLine();}

	public double nextDouble() throws IOException
	{
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if(x.charAt(0) == '-')
		{
			neg = true;
			start++;
		}
		for(int i = start; i < x.length(); i++)
			if(x.charAt(i) == '.')
			{
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			}
			else
			{
				sb.append(x.charAt(i));
				if(dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg?-1:1);
	}

	public boolean ready() throws IOException {return br.ready();}


}