#include <bits/stdc++.h>
using namespace std;

struct Mountain {
    long long x, y, h;
};

int n;
vector<Mountain> a;
vector<int> dp;

int dfs(int v) {
    int &res = dp[v];
    if (res != -1) return res;

    res = 1;
    for (int to = 0; to < n; ++to) {
        if (a[to].x > a[v].x &&
            a[to].y > a[v].y &&
            a[to].h < a[v].h) {
            res = max(res, 1 + dfs(to));
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].x >> a[i].y >> a[i].h;
    }

    dp.assign(n, -1);

    cout << dfs(0) << '\n';
    return 0;
}