#include <bits/stdc++.h>
using namespace std;
int dp[600][600];
int c[505];
int find(int l, int r) {
  if (dp[l][r] != 1000000) return dp[l][r];
  if (l == r) return dp[l][r] = 1;
  if (l > r) return 0;
  int i;
  for (i = l; i <= r; i++) {
    if (c[i] == c[r] && i <= r - 2)
      dp[l][r] = min(dp[l][r], find(l, i - 1) + find(i + 1, r - 1));
    if (i == r || (i == r - 1 && c[i] == c[r]))
      dp[l][r] = min(dp[l][r], find(l, i - 1) + 1);
  }
  return dp[l][r];
}
int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  for (i = 0; i <= n + 1; i++)
    for (j = 0; j <= n + 1; j++) dp[i][j] = 1000000;
  for (i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
  }
  int ans = find(1, n);
  printf("%d\n", ans);
}
