#include <bits/stdc++.h>
using namespace std;
int n, a[505], f[505][505];
int cal(int l, int r) {
  if (l == r) return 1;
  if (l == r + 1) return 1 + (a[l] != a[r]);
  if (f[l][r]) return f[l][r];
  int tam = r - l + 1;
  if (a[l] == a[r]) tam = cal(l + 1, r - 1);
  for (int k = l; k < r; k++) tam = min(tam, cal(l, k) + cal(k + 1, r));
  f[l][r] = tam;
  return tam;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  printf("%d", cal(1, n));
  return 0;
}
