#include <bits/stdc++.h>
using namespace std;
int n, c[510], dp[510][510];
int solve(int l, int r) {
  int i, j, k, ans = 10000007;
  if (l == r) return dp[l][r] = 1;
  if (l > r) return 1007;
  if (dp[l][r] == -1) {
    ans = 1 + solve(l + 1, r);
    if (c[l] == c[l + 1]) {
      int sm = 1;
      if (l + 2 <= r) sm += solve(l + 2, r);
      ans = min(ans, sm);
    }
    for (k = l + 2; k <= r; k++)
      if (c[l] == c[k]) {
        int sm = solve(l + 1, k - 1);
        if (k + 1 <= r) sm += solve(k + 1, r);
        ans = min(ans, sm);
      }
    dp[l][r] = ans;
  }
  return dp[l][r];
}
int main() {
  int i, j, k, ans;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &c[i]);
  for (i = 0; i <= n + 1; i++)
    for (j = 0; j <= n + 1; j++) dp[i][j] = -1;
  printf("%d\n", solve(0, n - 1));
  return 0;
}
