#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
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] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> ary[i];
  }
  cout << solve(ary, n + 1, dp, 0, 0) << endl;
  return 0;
}
