#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long n;
  cin >> n;
  vector<pair<long, pair<long, long> > > a;
  vector<long> t(n), r(n);
  for (long i = 0, l; i < n; i++) {
    cin >> l >> r[i] >> t[i];
    --t[i];
    a.push_back({l, {0, i}});
    a.push_back({r[i], {1, i}});
  }
  sort(a.begin(), a.end());
  set<pair<long, long> > s[2];
  long ans = n;
  for (auto it : a) {
    long cur = it.second.second;
    if (it.second.first) {
      long tmp = t[cur] ^ 1;
      if (s[t[cur]].count({r[cur], cur}) && !s[tmp].empty()) {
        ans--;
        s[tmp].erase(s[tmp].begin());
      }
      if (s[t[cur]].count({r[cur], cur})) s[t[cur]].erase({r[cur], cur});
    } else
      s[t[cur]].insert({r[cur], cur});
  }
  cout << ans;
  return 0;
}
