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 = 300010;
struct Input {
  int l, r, op;
  Input(int l = 0, int r = 0, int op = 0) : l(l), r(r), op(op) {}
} input[N];
int n, m, num[N * 6], val[N * 6], tree[N * 24], lazy_tag[N * 24] = {0},
                                                             pre[N * 6];
void build(int l, int r, int id) {
  if (l == r) {
    tree[id] = val[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, id << 1);
  build(mid + 1, r, id << 1 | 1);
  tree[id] = tree[id << 1] + tree[id << 1 | 1];
}
void push_down(int id, int l, int r) {
  int mid = (l + r) >> 1;
  lazy_tag[id << 1] = lazy_tag[id << 1 | 1] = lazy_tag[id];
  if (lazy_tag[id] == 1) {
    if (l > 0)
      tree[id << 1] = pre[mid] - pre[l - 1];
    else
      tree[id << 1] = pre[mid];
    tree[id << 1 | 1] = pre[r] - pre[mid];
  } else
    tree[id << 1] = tree[id << 1 | 1] = 0;
  lazy_tag[id] = 0;
}
void add(int l, int r, int a, int b, int id) {
  if (l >= a && r <= b) {
    if (l > 0)
      tree[id] = pre[r] - pre[l - 1];
    else
      tree[id] = pre[r];
    lazy_tag[id] = 1;
    return;
  }
  if (lazy_tag[id]) push_down(id, l, r);
  int mid = (l + r) >> 1;
  if (mid >= a) add(l, mid, a, b, id << 1);
  if (mid < b) add(mid + 1, r, a, b, id << 1 | 1);
  tree[id] = tree[id << 1] + tree[id << 1 | 1];
}
void zero(int l, int r, int a, int b, int id) {
  if (l >= a && r <= b) {
    tree[id] = 0;
    lazy_tag[id] = -1;
    return;
  }
  if (lazy_tag[id]) push_down(id, l, r);
  int mid = (l + r) >> 1;
  if (mid >= a) zero(l, mid, a, b, id << 1);
  if (mid < b) zero(mid + 1, r, a, b, id << 1 | 1);
  tree[id] = tree[id << 1] + tree[id << 1 | 1];
}
int main() {
  scanf("%d%d", &n, &m);
  int l, r, op, id = 0, tmp_num[N << 1];
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &l, &r, &op);
    input[i].l = l;
    input[i].r = r;
    input[i].op = op;
    tmp_num[id++] = l;
    tmp_num[id++] = r;
  }
  sort(tmp_num, tmp_num + id);
  int tmp_q = unique(tmp_num, tmp_num + id) - tmp_num;
  int q = 0;
  if (tmp_num[0] > 1) num[q++] = 1;
  for (int i = 0; i < tmp_q - 1; ++i) {
    int ca = tmp_num[i + 1] - tmp_num[i];
    num[q++] = tmp_num[i];
    if (ca >= 2) num[q++] = tmp_num[i] + 1;
    if (ca > 2) num[q++] = tmp_num[i + 1] - 1;
  }
  int last_num = tmp_num[tmp_q - 1];
  num[q++] = last_num;
  if (n - last_num >= 1) num[q++] = last_num + 1;
  num[q++] = n + 1;
  for (int i = 0; i < q - 1; ++i) val[i] = num[i + 1] - num[i];
  --q;
  pre[0] = val[0];
  for (int i = 1; i < q; ++i) pre[i] = pre[i - 1] + val[i];
  build(0, q - 1, 1);
  for (int i = 0; i < m; ++i) {
    l = input[i].l;
    r = input[i].r;
    op = input[i].op;
    int lr = lower_bound(num, num + q, l) - num;
    int rr = lower_bound(num, num + q, r) - num;
    if (op == 1)
      zero(0, q - 1, lr, rr, 1);
    else
      add(0, q - 1, lr, rr, 1);
    printf("%d\n", tree[1]);
  }
  return 0;
}