#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e6 + 9;
int l[MAXN], r[MAXN], t[MAXN];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> inv;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i] >> t[i];
    t[i]--;
    inv.emplace_back(l[i], i), inv.emplace_back(r[i] + 1, -i);
  }
  sort(inv.begin(), inv.end());
  multiset<int> black, red;
  int matching = 0;
  for (int i = 0; i < 2 * n; i++) {
    int x = inv[i].first;
    int idx = inv[i].second;
    if (idx < 0) {
      idx *= -1;
      if (t[idx]) {
        auto it = black.find(r[idx]);
        if (it != black.end()) {
          black.erase(it);
          if ((int)red.size()) matching++, red.erase(red.begin());
        }
      } else {
        auto it = red.find(r[idx]);
        if (it != red.end()) {
          red.erase(it);
          if ((int)black.size()) matching++, black.erase(black.begin());
        }
      }
    } else {
      if (t[idx]) {
        black.insert(r[idx]);
      } else {
        red.insert(r[idx]);
      }
    }
  }
  cout << n - matching << '\n';
}
