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 twords {
    public static void main(String[] args) {
        InputReader s=new InputReader(System.in);
        int n=s.nextInt(),q=s.nextInt();
        TreeSet<Integer> t=new TreeSet<Integer>();
        for (int i=1;i<=n;i++) {
            t.add(i);
        }
        HashMap<Integer,ArrayList<Integer>> busy =new HashMap<Integer,ArrayList<Integer>>();
        int k=0,d=0,time=0,count=0;
        boolean b=true;
        for (int i=1;i<=1000001;i++){
             
            if(b && count<q){
             time=s.nextInt();
             count++;
            b=false;
        }
            if(time==i){
                b=true;
             k=s.nextInt();
             d=s.nextInt();
            }
           if(busy.containsKey(i)){
            ArrayList<Integer> tmp=busy.get(i);
            for (int j=0;j<tmp.size();j++) {
                t.add(tmp.get(j));
            }
           }
           

    if(time==i){
            if(k<=t.size()){
                //System.out.println("here");
                int ans=0;
                ArrayList<Integer> arr=new ArrayList<Integer>();
                while(k>0){
                    int x=t.first();
                    ans+=x;
                    arr.add(x);
                   // busy.put(x,time+d);
                    t.remove(x);
                    k--;
                }
                //System.out.println("machines are "+arr);
                if(busy.containsKey(time+d)){
                    ArrayList<Integer> tmp=busy.get(time+d);
                    for (int j=0;j<tmp.size();j++) {
                        arr.add(tmp.get(j));
                    }
                }
                busy.put(time+d,arr);
                System.out.println(ans);
            }
            else{
                System.out.println(-1);
            }
        }
    }

        

        }   

        public static boolean isPrime(long n) {
          if(n<=1)
            return false;
          if(n > 2 && (n & 1) == 0)
           return false;
         for(int i = 3; i * i <= n; i += 2)
            if (n % i == 0) 
                return false;
        return true;
    }

        private static long gcd(long number1, long number2) { 
        if(number2 == 0){ 
        return number1;
        }

        return gcd(number2, number1%number2);
        }

        private static long lcm(long a, long b)
        {
         return a * (b / gcd(a, b));
        }

        static long power(long x, long y)
        {
            if( y == 0)
            return 1;
            else if (y%2 == 0)
            return power(x, y/2)*power(x, y/2);
            else
            return x*power(x, y/2)*power(x, y/2); 
        }   





        static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
     
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
     
        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
     
        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
     
        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
     
        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
     
        public String nextToken() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
     
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }
     
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    }
