#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
const int inf = 0x3f3f3f3f;
int n;
int niz[maxn];
int dp[maxn][maxn];
int f(int a, int b) {
  int &ret = dp[a][b];
  if (ret != -1) return ret;
  if (a > b) return 1;
  ret = inf;
  if (niz[a] == niz[b]) ret = min(ret, f(a + 1, b - 1));
  for (int i = a + 1; i <= b; i++) ret = min(ret, f(a, i - 1) + f(i, b));
  return ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", niz + i);
  printf("%d\n", f(0, n - 1));
  return 0;
}
