#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pi3 = pair<int, pii>;
const int NN = 502020;
int st[NN], ed[NN], t[NN];
set<pii> ss[4];
int main() {
  int n;
  cin >> n;
  vector<pi3> vec;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", st + i, ed + i, t + i);
    vec.push_back(pi3(st[i], pii(1, i)));
    vec.push_back(pi3(ed[i], pii(2, i)));
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  for (auto p : vec) {
    if (p.second.first == 2) {
      int i = p.second.second;
      int j = t[i];
      int k = 3 - j;
      if (ss[j].count(pii(ed[i], i)) && ss[k].size()) {
        ans++;
        ss[k].erase(ss[k].begin());
      }
      if (ss[j].count(pii(ed[i], i))) {
        ss[j].erase(ss[j].find(pii(ed[i], i)));
      }
    } else {
      ss[t[p.second.second]].insert(pii(ed[p.second.second], p.second.second));
    }
  }
  cout << n - ans << endl;
  return 0;
}
