#include <bits/stdc++.h>
using namespace std;
int max1[300002];
int seg[300002];
int findmax(int b, int z, int size) {
  if (z >= size)
    return z;
  else if (b > max1[0])
    return (-1);
  else if (b < max1[z]) {
    if (b < max1[2 * z + 2]) {
      return findmax(b, 2 * z + 2, size);
    } else
      return findmax(b, 2 * z + 1, size);
  }
}
void modify1(int value, int pos) {
  max1[pos] = value;
  if (pos != 0) {
    if ((pos) % 2 == 1) {
      if (max1[pos] > max1[pos + 1]) {
        modify1(max1[pos], (pos - 1) / 2);
      }
    } else if (pos % 2 == 0) {
      if (max1[pos] > max1[pos - 1]) {
        modify1(max1[pos], (pos - 2) / 2);
      }
    }
  }
}
void modify(int value, int pos) {
  seg[pos] = value;
  if (pos != 0) {
    if ((pos) % 2 == 1) {
      if (seg[pos] > seg[pos + 1]) {
        modify(seg[pos], (pos - 1) / 2);
      }
    } else if (pos % 2 == 0) {
      if (seg[pos] > seg[pos - 1]) {
        modify(seg[pos], (pos - 2) / 2);
      }
    }
  }
}
int query(int lpos, int rpos, int pos, int start, int end) {
  if ((lpos == start) && (rpos == end)) {
    return seg[pos];
  } else {
    int mid = (start + end) / 2;
    if (lpos > mid) {
      return query(lpos, rpos, 2 * pos + 2, mid + 1, end);
    } else if (rpos <= mid) {
      return query(lpos, rpos, 2 * pos + 1, start, mid);
    } else {
      if (query(mid + 1, rpos, 2 * pos + 2, mid + 1, end) >
          query(lpos, mid, 2 * pos + 1, start, mid))
        return query(mid + 1, rpos, 2 * pos + 2, mid + 1, end);
      else
        return query(lpos, mid, 2 * pos + 1, start, mid);
    }
  }
}
int main() {
  int a, b, c = -2, d, g, n, n1, p, m = 0, size = 1;
  cin >> n;
  n1 = n;
  for (;;) {
    n1 = n1 / 2;
    m++;
    if (n1 < 1) break;
  }
  for (a = 1; a <= m; a++) {
    size = size * 2;
  }
  size = size - 1;
  for (a = 0; a < size; a++) {
    seg[a] = 0;
    max1[a] = 0;
  }
  int e[n], f[n];
  for (a = 0; a <= n - 1; a++) {
    cin >> e[a];
  }
  f[0] = 0;
  for (a = 1; a <= n - 1; a++) {
    f[a] = 0;
    c = -2;
    modify1(e[a - 1], size + a - 1);
    if (e[a] < e[a - 1]) {
      f[a] = 1;
      modify(1, size + a);
    } else if (e[a] > e[a - 1]) {
      if (findmax(e[a], 0, size) == (-1)) {
        f[a] = 0;
      } else {
        c = findmax(e[a], 0, size) - size;
        modify((query(size + c + 1, size + a - 1, 0, size, size * 2) + 1),
               size + a);
      }
    }
  }
  cout << seg[0];
}
