#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = vector<int>;
int main(int argc, char* argv[]) {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  int n;
  cin >> n;
  vector<array<int, 4>> segs(n);
  vector<array<int, 3>> evts;
  for (int i = (0); i < (n); ++i) {
    int l, r, t;
    cin >> l >> r >> t;
    t--;
    segs[i] = {l, r, t, 0};
    evts.push_back({l, 0, i});
    evts.push_back({r, 1, i});
  }
  sort((evts).begin(), (evts).end());
  int pairs = 0;
  set<array<int, 2>> active_sides[2];
  for (auto [t, type, i] : evts) {
    if (type) {
      auto [l, r, t, m] = segs[i];
      if (!m) {
        active_sides[t].erase(active_sides[t].find({r, i}));
        auto& other_side = active_sides[1 - t];
        if (other_side.empty()) continue;
        auto [_, oi] = *other_side.begin();
        segs[oi][3] = 1;
        other_side.erase(other_side.begin());
        pairs++;
      }
    } else {
      active_sides[segs[i][2]].insert({segs[i][1], i});
    }
  }
  cout << n - pairs;
  cout.flush();
  return 0;
}
