#include <bits/stdc++.h>
using namespace std;
long long dp[505][505];
long long a[505];
long long solve(long long i, long long j) {
  if (i > j) return 0;
  if (i == j) return 1;
  if (j - i == 1) {
    if (a[i] == a[j]) return 1;
    return 2;
  }
  if (dp[i][j] != -1) return dp[i][j];
  long long ans = 1 + solve(i, j - 1);
  for (long long k = i; k <= j - 1; k++) {
    if (a[k] == a[j]) {
      ans = min(ans, solve(i, k - 1) + solve(k + 1, j - 1) + ((j - k) == 1));
    }
  }
  if (a[i] == a[j]) ans = min(ans, solve(i + 1, j - 1));
  return dp[i][j] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long i;
  for (i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      dp[i][j] = -1;
    }
  }
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cout << solve(1, n) << '\n';
}
