#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000;
int n;
int l[N], r[N], t[N];
set<pair<int, int>> st[2];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < int(n); ++i) scanf("%d%d%d", &l[i], &r[i], &t[i]), --t[i];
  vector<pair<int, pair<int, int>>> ev;
  for (int i = 0; i < int(n); ++i) {
    ev.push_back(make_pair(l[i], make_pair(0, i)));
    ev.push_back(make_pair(r[i], make_pair(1, i)));
  }
  sort((ev).begin(), (ev).end());
  int ans = 0;
  for (auto it : ev) {
    int i = it.second.second;
    if (it.second.first) {
      int j = t[i];
      int k = j ^ 1;
      if (st[j].count(make_pair(r[i], i)) && !st[k].empty()) {
        ++ans;
        st[k].erase(st[k].begin());
      }
      if (st[j].count(make_pair(r[i], i))) st[t[i]].erase(make_pair(r[i], i));
    } else {
      st[t[i]].insert(make_pair(r[i], i));
    }
  }
  printf("%d\n", n - ans);
}
