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>
const long long MAX_N = 3e5 + 100;
const long long MAX_E = 4500000 + 100;
const long long MOD = 1e9 + 7;
using namespace std;
vector<pair<int, pair<int, int>>> qs;
vector<int> ps;
int seg[MAX_E];
int mg[MAX_E];
int mv[MAX_E];
unordered_map<int, int> mp;
int n, q;
int y;
void build(int k) {
  if (k >= y) {
    mg[k] = seg[k];
    return;
  }
  build(k * 2);
  build(k * 2 + 1);
  seg[k] = seg[k * 2] + seg[k * 2 + 1];
  mg[k] = seg[k];
}
void down(int k, int l, int r) {
  if (mv[k * 2] != mv[k]) {
    if (mv[k] == 1)
      seg[k * 2] -= seg[k * 2];
    else
      seg[k * 2] += mg[k * 2] - seg[k * 2];
  }
  if (mv[k * 2 + 1] != mv[k]) {
    if (mv[k] == 1)
      seg[k * 2 + 1] -= seg[k * 2 + 1];
    else
      seg[k * 2 + 1] += mg[k * 2 + 1] - seg[k * 2 + 1];
  }
  mv[k * 2] = mv[k];
  mv[k * 2 + 1] = mv[k];
  mv[k] = 0;
}
void change(int l, int r, int a, int b, int k, int x) {
  if (r < a or b < l) return;
  if (a <= l and r <= b) {
    if (mv[k] == x) return;
    mv[k] = x;
    if (x == 1) {
      seg[k] = 0;
    } else {
      seg[k] = mg[k];
    }
    return;
  }
  if (mv[k]) down(k, l, r);
  int mid = (l + r) / 2;
  change(l, mid, a, b, k * 2, x);
  change(mid + 1, r, a, b, k * 2 + 1, x);
  seg[k] = seg[k * 2] + seg[k * 2 + 1];
}
int main() {
  cin >> n;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int k, l, r;
    scanf("%d%d%d", &l, &r, &k);
    qs.push_back({k, {l, r}});
    ps.push_back(l);
    ps.push_back(r);
  }
  sort(ps.begin(), ps.end());
  int last = 0;
  int m = 0;
  for (int i = 0; i < ps.size(); ++i) {
    if (ps[i] == last) continue;
    if (ps[i] - last == 1) {
      last = ps[i];
      m++;
      continue;
    }
    last = ps[i];
    m += 2;
  }
  if (last != n) m++;
  last = 0;
  y = (1ll << ((int)ceil(log2(m))));
  int pt = 0;
  for (int i = 0; i < ps.size(); ++i) {
    if (ps[i] == last) continue;
    if (ps[i] - last == 1) {
      last = ps[i];
      seg[pt + y] = 1;
      mp[ps[i]] = pt;
      pt++;
      continue;
    }
    seg[pt + y] = ps[i] - last - 1;
    seg[pt + 1 + y] = 1;
    pt++;
    mp[ps[i]] = pt;
    pt++;
    last = ps[i];
  }
  if (last != n) seg[pt + y] = n - last;
  build(1);
  for (int i = 0; i < q; ++i) {
    change(0, y - 1, mp[qs[i].second.first], mp[qs[i].second.second], 1,
           qs[i].first);
    printf("%d\n", seg[1]);
  }
  return 0;
}