#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
int n, ans, ncomp, r[2 * MAXN];
vector<tuple<int, int, int, int>> e;
set<pair<int, int>> s[2];
int main() {
  scanf("%d", &n);
  for (int i = 1, l, t; i <= n; i++)
    scanf("%d %d %d", &l, &r[i], &t), t--, e.emplace_back(l, 0, t, i),
        e.emplace_back(r[i], 1, t, i);
  sort(e.begin(), e.end());
  for (auto [x, o, t, id] : e) {
    if (o == 0) {
      s[t].insert({r[id], id});
    } else {
      if (!s[!t].empty() && s[t].count({r[id], id}))
        ans++, s[!t].erase(s[!t].begin());
      s[t].erase({r[id], id});
    }
  }
  printf("%d\n", n - ans);
}
