#include <bits/stdc++.h>
using namespace std;
int f[504][504], a[504];
int read() {
  int x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '0') f = -1;
  } while (ch > '9' || ch < '0');
  do {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
int search(int l, int r) {
  if (f[l][r] != -1) return f[l][r];
  if (l == r)
    return f[l][r] = 1;
  else if (l == r - 1)
    return f[l][r] = ((a[l] == a[r]) ? 1 : 2);
  if (a[l] == a[r])
    f[l][r] = search(l + 1, r - 1);
  else
    f[l][r] = 1e9 + 7;
  for (int i = l; i < r; i++)
    f[l][r] = min(f[l][r], search(l, i) + search(i + 1, r));
  return f[l][r];
}
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  memset(f, -1, sizeof(f));
  printf("%d", search(1, n));
}
