#include <bits/stdc++.h>
using namespace std;
int n;
int a[505];
int vis[505][505];
int dp[505][505], can[505][505];
void dfs(int nl, int nr) {
  if (nl >= nr) return;
  if (vis[nl][nr]) return;
  vis[nl][nr] = 1;
  if (nl + 1 == nr) {
    if (a[nl] == a[nr]) {
      can[nl][nr] = a[nl] + 1;
      dp[nl][nr] = 1;
      return;
    } else {
      dp[nl][nr] = 2;
      return;
    }
  }
  for (int i = nl + 1; i <= nr; i++) {
    dfs(nl, i - 1);
    dfs(i, nr);
    dp[nl][nr] = min(dp[nl][nr], dp[nl][i - 1] + dp[i][nr]);
    if (can[nl][i - 1] == can[i][nr] && can[nl][i - 1] != 0) {
      dp[nl][nr] = min(dp[nl][nr], dp[nl][i - 1] + dp[i][nr] - 1);
      can[nl][nr] = can[nl][i - 1] + 1;
    }
  }
  return;
}
int main() {
  memset(dp, 0x3f, sizeof(dp));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    dp[i][i] = 1;
    can[i][i] = a[i];
  }
  dfs(1, n);
  printf("%d\n", dp[1][n]);
}
