#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e3 + 100;
const int mod = 998244353;
int a[maxn];
int dp[maxn][2000];
int n;
void dfs(int pos, int r) {
  for (int i = 1; i <= pos - 1; i++) {
    if (dp[i][pos - 1] == dp[pos][r]) {
      dp[i][r] = dp[i][pos - 1] + 1;
      dfs(i, r);
    }
  }
}
int d[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) dp[i][j] = INF;
    dp[i][i] = a[i];
  }
  for (int i = 1; i <= n; i++) dfs(i, i);
  for (int i = 1; i <= n; i++) {
    d[i] = d[i - 1] + 1;
    for (int j = 1; j <= i - 1; j++) {
      if (dp[j][i] == INF) continue;
      d[i] = min(d[i], d[j - 1] + 1);
    }
  }
  printf("%d\n", d[n]);
  return 0;
}
