#include <bits/stdc++.h>
using namespace std;
const int Maxn = 510;
int f[Maxn][Maxn], c[Maxn], n;
inline int Min(int a, int b) { return a > b ? b : a; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= n; i++) f[i][i] = 1;
  for (int step = 2; step <= n; step++) {
    for (int i = 1; i <= n - step + 1; i++) {
      int j = i + step - 1;
      f[i][j] = f[i + 1][j] + 1;
      for (int k = i + 2; k <= j; k++)
        if (c[i] == c[k]) f[i][j] = Min(f[i][j], f[i + 1][k - 1] + f[k + 1][j]);
      if (c[i] == c[i + 1]) f[i][j] = Min(f[i][j], 1 + f[i + 2][j]);
    }
  }
  printf("%d\n", f[1][n]);
  return 0;
}
