#include <bits/stdc++.h>
using namespace std;
template <class T>
void mxi(T &a, const T &b) {
  a = max(a, b);
}
template <class T>
void mni(T &a, const T &b) {
  a = min(a, b);
}
long double EPS = 1e-9;
long long n, dp[505][505], dp1[505], ar[505];
long long go(long long l, long long r) {
  if (l > r) return 0;
  if (l == r) return dp[l][l] = ar[l];
  long long &e = dp[l][r];
  if (e == -1) {
    e = 0;
    for (long long i = l; i <= r; i++) {
      long long x1 = go(l, i), x2 = go(i + 1, r);
      if (x1 == x2 && x1) e = x1 + 1;
    }
  }
  return e;
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> ar[i];
  memset(dp, -1, sizeof(dp));
  long long waste = go(0, n - 1);
  for (long long i = 0; i < n; i++) {
    dp1[i] = i + 1;
    for (long long j = 0; j <= i; j++) {
      if (!j) {
        if (dp[j][i]) dp1[i] = 1;
      } else {
        if (dp[j][i]) dp1[i] = min(dp1[i], dp1[j - 1] + 1);
      }
    }
  }
  cout << dp1[n - 1] << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, tab;
  t = 1;
  tab = t;
  while (t--) {
    solve();
  }
}
