#include <bits/stdc++.h>
using namespace std;
int n, c[505], d[505][505];
int f(int L, int R) {
  if (L >= R) return 1;
  if (d[L][R]) return d[L][R];
  int v = R - L + 1;
  if (c[L] == c[R]) v = min(v, f(L + 1, R - 1));
  for (int i = L; i < R; i++) v = min(v, f(L, i) + f(i + 1, R));
  d[L][R] = v;
  return v;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  printf("%d", f(1, n));
}
