#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline T gcd(T a, T b) {
  return __gcd(a, b);
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
long long modpow(long long a, long long n, long long temp) {
  long long res = 1, y = a;
  while (n > 0) {
    if (n & 1) res = (res * y) % temp;
    y = (y * y) % temp;
    n /= 2;
  }
  return res % temp;
}
long long ison(long long mask, long long pos) { return (mask & (1 << pos)); }
long long cbit(long long n) {
  long long k = 0;
  while (n) n &= (n - 1), k++;
  return k;
}
long long nbit(long long n) {
  long long k = 0;
  while (n) n /= 2, k++;
  return k;
}
long long mod = 1e9 + 7;
int sgn(long long x) { return x < 0 ? -1 : !!x; }
long long xo(long long i) {
  if ((i & 3) == 0) return i;
  if ((i & 3) == 1) return 1;
  if ((i & 3) == 2) return i + 1;
  return 0;
}
long long dp[505][505];
long long a[505];
int main() {
  long long i, j, k, l, m, n;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  for (l = 1; l <= n; l++) {
    for (long long beg = 0, end = l - 1; end < n; beg++, end++) {
      if (l == 1)
        dp[beg][end] = 1;
      else {
        dp[beg][end] = 1 + dp[beg + 1][end];
        if (a[beg] == a[beg + 1])
          dp[beg][end] = min(dp[beg][end], dp[beg + 2][end] + 1);
        for (long long match = beg + 2; match <= end; match++) {
          if (a[beg] == a[match]) {
            dp[beg][end] =
                min(dp[beg + 1][match - 1] + dp[match + 1][end], dp[beg][end]);
          }
        }
      }
    }
  }
  cout << dp[0][n - 1];
}
