#include <bits/stdc++.h>
using namespace std;
const int MAXN = 600;
const int INF = 100000000;
int n;
int ara[MAXN];
int dp[MAXN][MAXN];
int query(int lower, int upper) {
  if (dp[lower][upper] != -1) return dp[lower][upper];
  if (lower == upper) return dp[lower][upper] = 1;
  if (upper == lower + 1) {
    if (ara[lower] == ara[upper])
      return dp[lower][upper] = 1;
    else
      return dp[lower][upper] = 2;
  }
  int mini = INF;
  if (ara[lower] == ara[upper]) mini = query(lower + 1, upper - 1);
  for (int i = lower; i < upper; ++i) {
    if (ara[i] == ara[lower])
      mini = min(mini, query(lower, i) + query(i + 1, upper));
  }
  return dp[lower][upper] = mini;
}
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &ara[i]);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", query(0, n - 1));
  return 0;
}
