const int MAX = 10000;

int solve(long long ary[], int n, int dp[], int cnt,int depth) {

	if (dp[depth] != -1) {
		return dp[depth] + cnt;
	}

	if (depth >= n - 1)return cnt;

	int res = 0;
	for (int i = depth + 1; i < n; i++) {
		if (ary[depth] < ary[i]) {
			res = max(res, solve(ary, n, dp, cnt + 1, i));
		}
	}
	dp[depth] = res - cnt;
	return res;
}

int main() {
	int n;
	long long ary[MAX];
	int dp[MAX];
	

	cin >> n;

	for (int i = 0; i < n + 1; i++) {
		dp[i] = -1;
	}
	ary[0] = -1;
	for (int i = 1; i < n + 1; i++) {
		cin >> ary[i];
	}

	cout << solve(ary, n + 1, dp, 0, 0) << endl;

	return 0;
}