#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 300010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b, ans;
pair<pair<int, int>, int> A[MAXN];
set<pair<int, int> > st[2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i].first.second >> A[i].first.first >> A[i].second;
    A[i].second--;
  }
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    int l = A[i].first.second, r = A[i].first.first, c = A[i].second;
    auto it = st[c ^ 1].lower_bound({l, -1});
    if (it == st[c ^ 1].end())
      st[c].insert({r, i});
    else {
      ans++;
      st[c ^ 1].erase(it);
    }
  }
  cout << n - ans << "\n";
  return 0;
}
