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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


public class C_2_387 {
	public static void main(String args[]){
		Scan scan = new Scan(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		final int data[][] = new int[q][3];
		boolean occ[] = new boolean[n+1];
		
		PriorityQueue<task> heap = new PriorityQueue<task>(q,new Comparator<task>(){
			public int compare(task a,task b){
				int temp = Integer.compare(a.end,b.end);
				if(temp==0)
					return Integer.compare(a.ind,b.ind);
				return temp;
			}
		});
		
		int unocc = n;
		for(int i=0;i<q;i++){
			data[i][0] = scan.nextInt();
			data[i][1] = scan.nextInt();
			data[i][2] = scan.nextInt();
			
			while(heap.peek()!=null && heap.peek().end<=data[i][0]){
				task ind = heap.poll();
				unocc += ind.occupied.length;
				for(int j=0;j<ind.occupied.length;j++)
					occ[ind.occupied[j]] = false;
			}
			
			if(unocc>=data[i][1]){
				int temp[] = new int[data[i][1]];
				int end = 0;
				long ans = 0;
				for(int j=1;j<=n && end<data[i][1];j++){
					if(occ[j]==false){
						temp[end++] = j;
						ans += j;
						occ[j] = true;
					}
				}
				unocc -= data[i][1];
				task t = new task(i,data[i][0]+data[i][2],temp);
				heap.add(t);
				System.out.println(ans);
			}else{
				System.out.println("-1");
			}
		}
	}
	static class task{
		int ind;
		int end;
		int occupied[];
		task(int i,int e,int occ[]){
			ind = i;
			end = e;
			occupied = occ;
		}
	}
	static class Scan{
		BufferedReader br;
		StringTokenizer token;
		Scan(InputStream input){
			br = new BufferedReader(new InputStreamReader(input));
			token = null;
		}
		public String next(){
			while(token==null || !token.hasMoreTokens() ){
				try {
					token = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return token.nextToken();
		}
		public char readChar() throws IOException{
			return (char)br.read();
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
	}
}
