#include <bits/stdc++.h>
using namespace std;
int n, T[505][505], a[505];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 505; j++) T[i][j] = 505;
  for (int i = 1; i <= n; i++) T[i][i] = 1;
  for (int i = 1; i <= n - 1; i++)
    if (a[i] == a[i + 1]) T[i][i + 1] = 1;
  for (int kk = 1; kk <= n; kk++)
    for (int i = 1; i <= n - kk; i++) {
      int j = i + kk;
      for (int k = i; k <= j - 1; k++)
        T[i][j] = min(T[i][j], T[i][k] + T[k + 1][j]);
      for (int k = 0; k <= (j - i + 1) / 2; k++)
        if (a[i + k] != a[j - k])
          break;
        else if (i + k + 1 <= j - k - 1)
          T[i][j] = min(T[i][j], T[i + k + 1][j - k - 1]);
    }
  printf("%d", T[1][n]);
}
