#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<pair<long long, long long>, int>> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i].first.first >> a[i].first.second >> a[i].second;
  sort(a.begin(), a.end(),
       [&](pair<pair<long long, long long>, int> &p0,
           pair<pair<long long, long long>, int> &p1) {
         return p0.first.second < p1.first.second;
       });
  int res = 0;
  multiset<long long> st1, st2;
  for (int i = 0; i < n; i++) {
    if (a[i].second == 1) {
      if (st2.size()) {
        auto itr = st2.lower_bound(a[i].first.first);
        if (itr != st2.end()) {
          res++;
          st2.erase(itr);
        } else {
          st1.insert(a[i].first.second);
        }
      } else {
        st1.insert(a[i].first.second);
      }
    } else {
      if (st1.size()) {
        auto itr = st1.lower_bound(a[i].first.first);
        if (itr != st1.end()) {
          res++;
          st1.erase(itr);
        } else {
          st2.insert(a[i].first.second);
        }
      } else {
        st2.insert(a[i].first.second);
      }
    }
  }
  res = n - res;
  cout << res << "\n";
  return 0;
}
