#include <bits/stdc++.h>
using namespace std;
int n;
int c[505];
int dp[505][505];
bool ispalin(const int &l, const int &r) {
  for (int k = 0; l + k <= r; ++k) {
    if (c[l + k] != c[r - k]) return false;
  }
  return true;
}
int f(const int &l, const int &r) {
  if (dp[l][r] > -1)
    return dp[l][r];
  else if (ispalin(l, r))
    return dp[l][r] = 1;
  else {
    int ans = INT_MAX;
    if (c[l] == c[r]) {
      ans = min(ans, f(l + 1, r - 1));
    }
    for (int k = l; k < r; ++k) {
      if (c[l] == c[k]) {
        ans = min(ans, f(l, k) + f(k + 1, r));
      }
    }
    for (int k = l + 1; k <= r; ++k) {
      if (c[k] == c[r]) {
        ans = min(ans, f(l, k - 1) + f(k, r));
      }
    }
    return dp[l][r] = ans;
  }
}
int main() {
  scanf("%d", &n);
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; ++i) {
    dp[i][i] = 1;
    scanf("%d", &c[i]);
  }
  printf("%d\n", f(1, n));
  return 0;
}
