#include <bits/stdc++.h>
int scan() {
  int noRead = 0;
  char p = getchar();
  for (; p < 33;) {
    p = getchar();
  }
  while (p > 32) {
    noRead = (noRead << 3) + (noRead << 1) + (p - '0');
    p = getchar();
  }
  return noRead;
}
long long int lscan() {
  long long int noRead = 0;
  char p = getchar();
  for (; p < 33;) {
    p = getchar();
  }
  while (p > 32) {
    noRead = (noRead << 3) + (noRead << 1) + (p - '0');
    p = getchar();
  }
  return noRead;
}
using namespace std;
int dp[501][501];
int vec[501];
int f(int l, int r) {
  if (l > r) return 0;
  if (l == r) return 1;
  if (dp[l][r] != -1) return dp[l][r];
  int &ans = dp[l][r];
  ans = 100001;
  ans = min(ans, 1 + f(l + 1, r));
  for (int i = l + 2; i <= r; ++i) {
    if (vec[l] == vec[i]) {
      ans = min(ans, f(l + 1, i - 1) + f(i + 1, r));
    }
  }
  if (vec[l] == vec[l + 1]) ans = min(ans, 1 + f(l + 2, r));
  return ans;
}
int main(void) {
  int n = scan();
  for (int i = 0; i < n; ++i) vec[i] = scan();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) dp[i][j] = -1;
  printf("%d", f(0, n - 1));
  return 0;
}
