#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long long mod = 998244353;
int a[1000][1000], dp[1000][1000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j) dp[i][j] = j - i + 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i][i]);
    dp[i][i] = 1;
  }
  for (int len = 2; len <= n; ++len)
    for (int l = 1; l + len - 1 <= n; ++l) {
      int r = l + len - 1;
      for (int k = l; k <= r; ++k) {
        dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r]);
        if (dp[l][k] == 1 && dp[k + 1][r] == 1 && a[l][k] == a[k + 1][r])
          dp[l][r] = 1, a[l][r] = a[l][k] + 1;
      }
    }
  printf("%d\n", dp[1][n]);
  return 0;
}
