#include <bits/stdc++.h>
using namespace std;
int dp[505][505], n, A[505];
int rec(int l, int r) {
  if (dp[l][r] != -1) return dp[l][r];
  if (l >= r) return dp[l][r] = 1;
  int res = r - l + 1;
  if (A[l] == A[r]) res = min(rec(l + 1, r - 1), res);
  for (int i = l; i + 1 <= r; i++) res = min(rec(l, i) + rec(i + 1, r), res);
  return dp[l][r] = res;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  printf("%d\n", rec(1, n));
  return 0;
}
