#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int a[maxn], dp[maxn][maxn];
int n;
const int INF = (1 << 30) - 1;
int dfs(int l, int r) {
  if (l >= r) return 1;
  if (dp[l][r]) return dp[l][r];
  int res = INF;
  if (a[l] == a[r]) res = min(res, dfs(l + 1, r - 1));
  for (int i = l; i < r; i++) {
    res = min(res, dfs(l, i) + dfs(i + 1, r));
  }
  return dp[l][r] = res;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    memset(dp, 0, sizeof(dp));
    printf("%d\n", dfs(1, n));
  }
  return 0;
}
