#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
int n, l, r, t;
vector<tuple<int, int, int, int, int> > events;
multiset<tuple<int, int> > active[2];
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> r >> t;
    t -= 1;
    if (0) printf("found a segment [%d, %d](c = %d)\n", l, r, t);
    events.emplace_back(l, 0, l, r, t);
    events.emplace_back(r, 1, l, r, t);
  }
  sort(events.begin(), events.end());
  int m = 0;
  for (auto [pos, op, l, r, t] : events) {
    if (0) printf("process event <%d>(%d)[%d, %d](c = %d)\n", pos, op, l, r, t);
    if (op == 0) {
      active[t].insert(make_tuple(r, l));
    } else {
      auto self = active[t].find(make_tuple(r, l));
      auto it = active[!t].lower_bound(make_tuple(l, -1));
      if (self != active[t].end() && it != active[!t].end()) {
        m += 1;
        active[t].erase(self);
        active[!t].erase(it);
      }
    }
  }
  cout << (n - m) << endl;
}
