#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
int n;
int right_end[500500];
set<pair<int, int>> st[2];
bool used[500500];
vector<pair<pair<int, int>, pair<int, int>>> events;
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int l, r, color;
    cin >> l >> r >> color;
    right_end[i] = r;
    --color;
    events.push_back({{l, 0}, {i, color}});
    events.push_back({{r, 1}, {i, color}});
  }
  sort(events.begin(), events.end());
  int maximum_matching = 0;
  for (auto &event : events) {
    int pos = event.first.first, type = event.first.second;
    int id = event.second.first, color = event.second.second;
    if (used[id]) continue;
    if (type == 1) {
      int rev_color = 1 - color;
      if (!st[rev_color].empty() && st[rev_color].rbegin()->first >= pos) {
        ++maximum_matching;
        auto it = st[rev_color].lower_bound({pos, -1});
        int cur_id = it->second;
        used[cur_id] = 1;
        st[rev_color].erase(it);
      }
      st[color].erase({pos, id});
    } else {
      st[color].insert({right_end[id], id});
    }
  }
  cout << n - maximum_matching << "\n";
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
