#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  pair<long long, long long> a[n];
  long long c[n];
  for (int i = 0, ggdem = n; i < ggdem; ++i)
    cin >> a[i].first >> a[i].second >> c[i], c[i]--;
  vector<pair<pair<long long, long long>, long long>> v;
  for (int i = 0, ggdem = n; i < ggdem; ++i) {
    v.push_back({{a[i].first, 1}, i});
    v.push_back({{a[i].second + 1, -1}, i});
  }
  sort(v.begin(), v.end());
  set<long long> st[2];
  set<pair<long long, long long>> r[2];
  long long res = 0;
  for (int i = 0, ggdem = ((int)v.size()); i < ggdem; ++i) {
    if (v[i].first.second == 1) {
      st[c[v[i].second]].insert(v[i].second);
      r[c[v[i].second]].insert({a[v[i].second].second, v[i].second});
    } else {
      if (st[c[v[i].second]].count(v[i].second)) {
        if (((int)r[c[v[i].second] ^ 1].size())) {
          auto it = r[c[v[i].second] ^ 1].begin();
          res++;
          st[c[v[i].second] ^ 1].erase(it->second);
          r[c[v[i].second] ^ 1].erase({a[it->second].second, it->second});
        }
        st[c[v[i].second]].erase(v[i].second);
        r[c[v[i].second]].erase({a[v[i].second].second, v[i].second});
      }
    }
  }
  cout << n - res << "\n";
  return 0;
}
