#include <bits/stdc++.h>
#pragma GCC optimize(2)
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 2e5 + 10;
int L[N], R[N], t[N];
int n;
struct node {
  int a, b, c;
};
multiset<int> s[3];
vector<node> vec;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    L[i] = read(), R[i] = read(), t[i] = read();
    t[i]--;
  }
  for (int i = 1; i <= n; i++) {
    vec.push_back(node{L[i], i, 0});
    vec.push_back(node{R[i], i, 1});
  }
  sort(vec.begin(), vec.end(), [](node t1, node t2) {
    if (t1.a == t2.a) {
      return t1.c < t2.c;
    } else {
      return t1.a < t2.a;
    };
  });
  int pi = 0;
  for (auto k : vec) {
    int id = k.b;
    int col = t[id];
    if (k.c == 1) {
      if (s[col].find(R[id]) != s[col].end()) {
        if (s[col ^ 1].size()) {
          pi++;
          s[col ^ 1].erase(s[col ^ 1].begin());
        }
        s[col].erase(s[col].find(R[id]));
      }
    } else {
      s[col].insert(R[id]);
    }
  }
  cout << n - pi << endl;
  return 0;
}
