#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, b = getchar(), c = 1;
  while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a * c;
}
int n, ans;
pair<int, pair<int, int> > a[200005];
multiset<int> s;
int main() {
  n = read(), ans = n;
  for (int i = 0; i < n; i++) {
    int l = read(), r = read(), x = read();
    if (x & 1)
      a[i] = (pair<int, pair<int, int> >){l, {x, -r}};
    else
      a[i] = (pair<int, pair<int, int> >){r, {x, -l}};
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++)
    if (a[i].second.first & 1)
      s.insert(a[i].second.second);
    else {
      multiset<int>::iterator it = s.upper_bound(a[i].second.second);
      if (it != s.begin()) s.erase(--it), ans--;
    }
  cout << ans;
  return 0;
}
