#include <bits/stdc++.h>
using namespace std;
int a[510];
int dp[510][510];
int dfs(int i, int j) {
  if (dp[i][j]) return dp[i][j];
  if (i == j) {
    dp[i][j] = 1;
    return 1;
  }
  if (i + 1 == j) {
    if (a[i] == a[j])
      dp[i][j] = 1;
    else
      dp[i][j] = 2;
    return dp[i][j];
  }
  dp[i][j] = 10000;
  if (a[i] == a[j]) dp[i][j] = dfs(i + 1, j - 1);
  for (int k = i; k <= j - 1; 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]);
  printf("%d\n", dfs(1, n));
  return 0;
}
