#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
const int N = 505;
int n, dp[N][N], ans, a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  memset(dp, 0x3f3f3f3f, sizeof dp);
  for (int i = 1; i <= n; i++) dp[i][i] = 1, dp[i][i - 1] = 1;
  for (int len = 1; len <= n; len++) {
    for (int i = 1, j = len + i; j <= n; j++, i++) {
      if (a[i] == a[j]) dp[i][j] = min(dp[i + 1][j - 1], dp[i][j]);
      for (int k = i; k < j; k++)
        dp[i][j] = min(dp[i][k] + dp[k + 1][j], dp[i][j]);
    }
  }
  cout << dp[1][n];
  return 0;
}
