Problem: This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson!

Since Alex doesn't want to get expelled, he wants to know the number of working days left until the end of the term, so he can attend physical education lessons during these days. But in BSU calculating the number of working days is a complicated matter:

There are n days left before the end of the term (numbered from 1 to n), and initially all of them are working days. Then the university staff sequentially publishes q orders, one after another. Each order is characterised by three numbers l, r and k:

  * If k = 1, then all days from l to r (inclusive) become non-working days. If some of these days are made working days by some previous order, then these days still become non-working days; 
  * If k = 2, then all days from l to r (inclusive) become working days. If some of these days are made non-working days by some previous order, then these days still become working days. 



Help Alex to determine the number of working days left after each order!

Input

The first line contains one integer n, and the second line — one integer q (1 ≤ n ≤ 109, 1 ≤ q ≤ 3·105) — the number of days left before the end of the term, and the number of orders, respectively.

Then q lines follow, i-th line containing three integers li, ri and ki representing i-th order (1 ≤ li ≤ ri ≤ n, 1 ≤ ki ≤ 2).

Output

Print q integers. i-th of them must be equal to the number of working days left until the end of the term after the first i orders are published.

Example

Input

4
6
1 2 1
3 4 1
2 3 2
1 3 2
2 4 1
1 4 2


Output

2
0
2
3
1
4

Solution (in JAVA):

Solution:
//package practice.pset1;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class R915E {

    static TreeSet<Segment> set;
    static int ans;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        set = new TreeSet<>();
        int n = sc.nextInt();
        add(new Segment(1, n));
        int q = sc.nextInt();
        while(q -- > 0){
            int a= sc.nextInt();
            int b = sc.nextInt();
            int type = sc.nextInt();
            if(type == 2)
                add(new Segment(a, b));
            else
                remove(new Segment(a, b));
            pw.println(ans);
        }

        pw.flush();
        pw.close();
    }


    static void add(Segment s){
        // remove in between
        Segment nxt = set.higher(s);
        while(nxt != null && nxt.end <= s.end){
            set.remove(nxt);
            ans -= (nxt.end - nxt.start + 1);
            nxt = set.higher(nxt);
        }

        // merge left side
        Segment before  = set.lower(new Segment(s.start+1, s.end));
        if(before != null && before.end >= s.start){
            set.remove(before);
            ans -= (before.end-before.start + 1);
            s = new Segment(before.start, Math.max(before.end, s.end));
        }
        // merge right side
        Segment after = set.lower(new Segment(s.end+1, s.end+1));
        if(after != null && after.end >= s.end){
            set.remove(after);
            ans -= (after.end-after.start + 1);
            s = new Segment(Math.min(after.start, s.start), Math.max(after.end, s.end));
        }

        // add segment
        set.add(s);
        ans += (s.end - s.start + 1);

    }

    static void remove(Segment s){
        // remove in between
        Segment nxt = set.higher(s);
        while(nxt != null && nxt.end <= s.end){
            set.remove(nxt);
            ans -= (nxt.end - nxt.start + 1);
            nxt = set.higher(nxt);
        }

        // merge left side
        Segment before  = set.lower(new Segment(s.start+1, s.end));
        if(before != null){
            set.remove(before);
            ans -= (before.end - before.start + 1);
            Segment[] segArr = difference(before, s);
            for (int i = 0; i < segArr.length; i++) {
                set.add(segArr[i]);
                ans += (segArr[i].end - segArr[i].start + 1);
            }
        }
        // merge right side
        Segment after = set.lower(new Segment(s.end+1, s.end+1));
        if(after != null ){
            set.remove(after);
            ans -= (after.end - after.start + 1);
            Segment[] segArr = difference(after, s);
            for (int i = 0; i < segArr.length; i++) {
                set.add(segArr[i]);
                ans += (segArr[i].end - segArr[i].start + 1);
            }
        }
    }

    static Segment[] difference (Segment a, Segment s){
        if(a.end < s.start || a.start > s.end)
            return new Segment[]{a};
        if(a.start >= s.start && a.end <= s.end)
            return new Segment[]{};
        if(a.start < s.start && a.end > s.end){
            return new Segment[]{new Segment(a.start, s.start-1), new Segment(s.end+1, a.end)};
        }
        if(a.start < s.start)
            return new Segment[]{new Segment(a.start, s.start-1)};
        return new Segment[]{new Segment(s.end+1, a.end)};
    }
    static class Segment implements Comparable<Segment>{
        int start, end;

        public Segment(int start, int end) {
            this.start = start;
            this.end = end;
        }

        @Override
        public int compareTo(Segment segment) {
            return start - segment.start;
        }

        public String toString(){
            return start +" " + end;
        }
    }

    static class Scanner
    {
        StringTokenizer st; BufferedReader br;
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
        public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(new File(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 boolean ready() throws IOException {return br.ready();}
    }
}