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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, m;
struct sgt {
  int ls, rs, l, r, num, cnt, tag;
} s[6 * N];
int rt, P;
int a[2 * N], len;
void upd(int p) {
  s[p].num = ((s[s[p].ls].tag == -1) ? s[s[p].ls].num
                                     : (s[s[p].ls].tag * s[s[p].ls].cnt)) +
             ((s[s[p].rs].tag == -1) ? s[s[p].rs].num
                                     : (s[s[p].rs].tag * s[s[p].rs].cnt));
}
int build(int l, int r) {
  int p = ++P;
  s[p].l = l;
  s[p].r = r;
  s[p].tag = -1;
  if (l == r) {
    s[p].cnt = a[l + 1] - a[l];
    return p;
  }
  int mid = (s[p].l + s[p].r) >> 1;
  s[p].ls = build(l, mid);
  s[p].rs = build(mid + 1, r);
  upd(p);
  s[p].cnt = s[s[p].ls].cnt + s[s[p].rs].cnt;
  return p;
}
void pushd(int p) {
  if (s[p].tag == -1) return;
  s[p].num = ((s[p].tag == -1) ? s[p].num : (s[p].tag * s[p].cnt));
  s[s[p].ls].tag = s[s[p].rs].tag = s[p].tag;
  s[p].tag = -1;
}
void change(int p, int l, int r, int x) {
  if (s[p].l == l && s[p].r == r) {
    s[p].tag = x;
    return;
  }
  pushd(p);
  int mid = (s[p].l + s[p].r) >> 1;
  if (r <= mid)
    change(s[p].ls, l, r, x);
  else if (l > mid)
    change(s[p].rs, l, r, x);
  else {
    change(s[p].ls, l, mid, x);
    change(s[p].rs, mid + 1, r, x);
  }
  upd(p);
}
int ql[N], qr[N], qk[N];
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  a[++len] = 1;
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &ql[i], &qr[i], &qk[i]);
    a[++len] = ql[i];
    a[++len] = qr[i] + 1;
    qk[i] = 2 - qk[i];
  }
  a[++len] = n + 1;
  sort(a + 1, a + len + 1);
  len = unique(a + 1, a + len + 1) - (a + 1);
  rt = build(1, len - 1);
  for (i = 1; i <= m; i++) {
    ql[i] = lower_bound(a + 1, a + len + 1, ql[i]) - a;
    qr[i] = lower_bound(a + 1, a + len + 1, qr[i] + 1) - (a + 1);
  }
  for (i = 1; i <= m; i++) {
    change(rt, ql[i], qr[i], qk[i]);
    printf("%d\n",
           n - ((s[rt].tag == -1) ? s[rt].num : (s[rt].tag * s[rt].cnt)));
  }
  return 0;
}