#include <bits/stdc++.h>
using namespace std;
int n;
int l[400005], r[400005], t[400005];
vector<int> b;
vector<int> v1[400005], v2[400005], cnt[400005];
multiset<int> s;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &l[i], &r[i], &t[i]);
    b.push_back(l[i]);
    b.push_back(r[i]);
  }
  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());
  for (int i = 0; i < n; i++) {
    l[i] = lower_bound(b.begin(), b.end(), l[i]) - b.begin();
    r[i] = lower_bound(b.begin(), b.end(), r[i]) - b.begin();
    if (t[i] == 1)
      v1[l[i]].push_back(r[i]);
    else
      v2[l[i]].push_back(r[i]);
  }
  int ans = 0;
  for (int i = 0; i < 400005; i++) {
    for (int x : v2[i]) cnt[x].push_back(i);
    for (int x : v1[i]) s.insert(x);
    for (int x : cnt[i]) {
      if (s.empty()) break;
      auto it = s.lower_bound(x);
      if (it == s.end()) continue;
      ans++;
      s.erase(it);
    }
  }
  printf("%d\n", n - ans);
  return 0;
}
