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

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

bool cmp(const Mountain &A, const Mountain &B) {
    if (A.x != B.x) return A.x < B.x;
    if (A.y != B.y) return A.y < B.y;
    return A.h < B.h;
}

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

    int n;
    cin >> n;

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

    sort(a.begin(), a.end(), cmp);

    vector<int> dp(n, 1);
    int ans = 1;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            if (a[j].x < a[i].x &&
                a[j].y < a[i].y &&
                a[j].h > a[i].h) {
                dp[i] = max(dp[i], dp[j] + 1);
            }
        }
        ans = max(ans, dp[i]);
    }

    cout << ans << '\n';
    return 0;
}