#include <bits/stdc++.h>
using namespace std;
long long int n, ara[510], dp[510][510], dp2[510];
long long int f(long long int i, long long int j) {
  if (dp[i][j] != -1) return dp[i][j];
  if (i == j) return dp[i][j] = ara[i];
  long long int pref, suf;
  for (int k = i; k < j; k++) {
    pref = f(i, k);
    suf = f(k + 1, j);
    if (pref && pref == suf) return dp[i][j] = pref + 1;
  }
  return dp[i][j] = 0;
}
long long int f2(long long int i) {
  if (i >= n) return 0;
  if (dp2[i] != -1) return dp2[i];
  long long int res = 1 << 30;
  for (int k = i; k < n; k++) {
    if (f(i, k)) res = min(res, 1 + f2(k + 1));
  }
  return dp2[i] = res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ara[i];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) dp[i][j] = -1;
  for (int i = 0; i < n; i++) dp2[i] = -1;
  cout << f2(0) << endl;
  return 0;
}
