#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
int ans;
int l[maxn];
int r[maxn];
int t[maxn];
set<pair<int, int>> st[2];
vector<pair<pair<int, int>, pair<int, int>>> cache;
void in();
void solve();
void out();
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  in();
  solve();
  out();
}
void in() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i] >> t[i];
    l[i]--;
    t[i]--;
    cache.push_back({{l[i], 1}, {i, t[i]}});
    cache.push_back({{r[i], 0}, {i, t[i]}});
  }
  sort(cache.begin(), cache.end());
}
void solve() {
  ans = n;
  for (auto x : cache) {
    int i = x.second.first;
    if (x.first.second)
      st[x.second.second].insert({r[i], i});
    else {
      if (st[x.second.second].find({r[i], i}) != st[x.second.second].end() &&
          st[1 - x.second.second].size()) {
        ans--;
        auto y = *st[1 - x.second.second].begin();
        st[1 - x.second.second].erase(y);
      }
      st[x.second.second].erase({r[i], i});
    }
  }
}
void out() { cout << ans; }
