#include <bits/stdc++.h>
using namespace std;
int a[503], f[503][503];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    f[i][i] = 1;
  }
  for (int i = 1; i + 1 <= n; i++) f[i][i + 1] = (a[i] == a[i + 1] ? 1 : 2);
  for (int len = 3; len <= n; len++) {
    for (int i = 1; i + len - 1 <= n; i++) {
      int j = i + len - 1;
      if (a[i] == a[j])
        f[i][j] = f[i + 1][j - 1];
      else
        f[i][j] = 0x3f3f3f3f;
      for (int k = i; k + 1 <= j; k++) {
        f[i][j] = min(f[i][k] + f[k + 1][j], f[i][j]);
      }
    }
  }
  printf("%d\n", f[1][n]);
  return 0;
}
