#include <bits/stdc++.h>
using namespace std;
int dp[(500 + 10)][(500 + 10)];
int a[(500 + 10)];
int DFS(int i, int j) {
  if (dp[i][j] != -1) return dp[i][j];
  if (i == j) return 1;
  if (i > j) return 0;
  if (i + 1 == j) {
    if (a[i] == a[j])
      return 1;
    else
      return 2;
  }
  dp[i][j] = 0x3f3f3f3f;
  if (a[i] == a[j]) dp[i][j] = DFS(i + 1, j - 1);
  for (int k = i; k <= j; k++)
    dp[i][j] = min(dp[i][j], DFS(i, k) + DFS(k + 1, j));
  return dp[i][j];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(dp, (-1), sizeof(dp));
  printf("%d", (DFS(1, n)));
  return 0;
}
