#include <bits/stdc++.h>
using namespace std;
long long int dp[1005][1005] = {0};
int a[1005];
bool pal(int i, int j) {
  while (i < j) {
    if (a[i] != a[j]) return false;
    i++;
    j--;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) cin >> a[i];
  for (int i = 0; i <= n - 1; i++) dp[i][i] = 1;
  for (int i = 0; i <= n - 2; i++) dp[i][i + 1] = (a[i] == a[i + 1]) ? 1 : 2;
  for (int d = 2; d <= n - 1; d++) {
    for (int i = 0; i <= n - 1; i++) {
      int j = i + d;
      if (j > n - 1) continue;
      dp[i][j] = 1e18;
      if (a[i] == a[j]) dp[i][j] = dp[i + 1][j - 1];
      for (int k = i; k <= j - 1; k++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
      }
      if (pal(i, j)) dp[i][j] = 1;
    }
  }
  cout << dp[0][n - 1];
  return 0;
}
