#include <bits/stdc++.h>
using namespace std;
long long n, a[500], dp[500][500];
long long go(long long i, long long j) {
  if (i == j) return 1;
  if (i > j) return 0;
  if (j == (i + 1) && a[i] == a[j]) return 1;
  if (dp[i][j] != -1) return dp[i][j];
  dp[i][j] = INT_MAX;
  if (a[i] == a[j]) dp[i][j] = go(i + 1, j - 1);
  for (long long k = i; k < j; k++)
    dp[i][j] = min(dp[i][j], go(i, k) + go(k + 1, j));
  return dp[i][j];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << go(0, n - 1);
  return 0;
}
