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>
#pragma comment(linker, "/STACK:536870912")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
using namespace std;
template <typename T>
void _R(T &x) {
  cin >> x;
}
template <typename T>
void _R(vector<T> &x) {
  for (auto it = x.begin(); it != x.end(); it++) {
    _R(*it);
  }
}
void R() {}
template <typename T, typename... K>
void R(T &head, K &...tail) {
  _R(head);
  R(tail...);
}
template <typename T>
void _W(const T &x, const char c) {
  cout << x;
}
template <typename T>
void _W(const vector<T> &x, const char c) {
  for (auto it = x.cbegin(); it != x.cend(); it++) {
    if (it != x.cbegin()) putchar(c);
    _W(*it, c);
  }
}
void W() {}
template <typename T, typename... K>
void W(const T &head, const K &...tail) {
  _W(head, ' ');
  cout << (sizeof...(tail) ? ' ' : '\n') << flush;
  W(tail...);
}
const double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230;
template <typename T>
inline T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
inline void amin(T &x, T y) {
  if (x > y) x = y;
}
template <typename T>
inline void amax(T &x, T y) {
  if (x < y) x = y;
}
template <typename A, typename B>
class comp {
 public:
  bool operator()(const pair<A, B> &a, const pair<A, B> &b) {
    if (a.first != b.first)
      return a.first < b.first;
    else
      return a.first > b.first;
  }
};
long long fast_exp(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1LL) {
      res *= a;
      res %= 1000000007;
    }
    b >>= 1LL;
    a *= a;
    a %= 1000000007;
  }
  return res;
}
struct query {
  int l, r, k;
  query(int l, int r, int k) : l(l), r(r), k(k) {}
  query() : l(0), r(0), k(0) {}
};
const int Q = 300500;
int compression[2 * Q];
int segmentTree[8 * Q];
int lazy[8 * Q];
query queries[Q];
int n, q;
void preprocess(void) { return; }
void toggle(int v, int l, int r, int ql, int qr, int type) {
  if (lazy[v]) {
    if (l != r) {
      lazy[((v) << 1)] = lazy[v];
      lazy[(((v) << 1) + 1)] = lazy[v];
    }
    segmentTree[v] = (compression[r] - compression[l - 1]) * (lazy[v] == 2);
    lazy[v] = 0;
  }
  if (l > r or ql > r or qr < l) {
    return;
  }
  if (l >= ql and qr >= r) {
    lazy[v] = type;
    if (l != r) {
      lazy[((v) << 1)] = lazy[v];
      lazy[(((v) << 1) + 1)] = lazy[v];
    }
    segmentTree[v] = (compression[r] - compression[l - 1]) * (lazy[v] == 2);
    lazy[v] = 0;
    return;
  }
  int m = (l + r) >> 1;
  toggle(((v) << 1), l, m, ql, qr, type);
  toggle((((v) << 1) + 1), m + 1, r, ql, qr, type);
  segmentTree[v] = segmentTree[((v) << 1)] + segmentTree[(((v) << 1) + 1)];
  return;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int teeee;
  teeee = 1;
  for (int zeeee = (1); zeeee <= (teeee); zeeee++) {
    scanf("%d %d\n", &n, &q);
    int m = 0;
    compression[m++] = 0;
    compression[m++] = n;
    for (int i = (0); i <= ((int)(q)-1); i++) {
      int l, r, k;
      scanf("%d %d %d\n", &l, &r, &k);
      queries[i] = query(l, r, k);
      compression[m++] = l - 1;
      compression[m++] = r;
    }
    sort(compression, compression + m);
    m = unique(compression, compression + m) - compression;
    memset(lazy, 0, sizeof lazy);
    int l_ = lower_bound(compression, compression + m, 1) - compression;
    int r_ = lower_bound(compression, compression + m, n) - compression;
    toggle(1, 0, m - 1, l_, r_, 2);
    for (int i = (0); i <= ((int)(q)-1); i++) {
      int l =
          lower_bound(compression, compression + m, queries[i].l) - compression;
      int r =
          lower_bound(compression, compression + m, queries[i].r) - compression;
      toggle(1, 0, m - 1, l, r, queries[i].k);
      printf("%d\n", segmentTree[1]);
    }
  }
  cerr << ((double)clock() / (double)CLOCKS_PER_SEC) << endl;
  return 0;
}