#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 505;
long long dp[N][N], dp2[N];
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> ar(n);
  for (long long i = 0; i < n; i++) cin >> ar[i];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++)
      if (i == j)
        dp[i][j] = ar[i];
      else
        dp[i][j] = -1;
  for (long long sz = 1; sz <= n - 1; sz++) {
    for (long long i = sz; i < n; i++) {
      long long j = i - sz;
      if (j == i) continue;
      for (long long k = j; k <= i; k++) {
        if (dp[j][k] != -1 && dp[j][k] == dp[k + 1][i]) dp[j][i] = dp[j][k] + 1;
      }
    }
  }
  for (long long i = 0; i < n; i++) dp2[i] = i + 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j <= i; j++) {
      if (dp[j][i] == -1) continue;
      if (j == 0)
        dp2[i] = 1;
      else
        dp2[i] = min(dp2[i], dp2[j - 1] + 1);
    }
  }
  cout << dp2[n - 1];
}
