#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 500 + 5;
int n;
int arr[MAX_N];
int memo[MAX_N][MAX_N];
int memo2[MAX_N][MAX_N];
int dp(int l, int r) {
  if (l == r) return memo[l][r] = arr[l];
  if (memo[l][r] != -1) return memo[l][r];
  for (int i = l; i < r; ++i) {
    if (dp(l, i) == dp(i + 1, r) && dp(l, i) > 0)
      return memo[l][r] = dp(l, i) + 1;
  }
  return memo[l][r] = -10;
}
int solve(int l, int r) {
  if (memo[l][r] != -10) return 1;
  if (memo2[l][r] != -1) return memo2[l][r];
  int mini = n;
  for (int i = l; i < r; ++i) {
    mini = min(mini, solve(l, i) + solve(i + 1, r));
  }
  return memo2[l][r] = mini;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  memset(memo, -1, sizeof memo);
  memset(memo2, -1, sizeof memo2);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  dp(0, n - 1);
  cout << solve(0, n - 1) << '\n';
  return 0;
}
