#include <bits/stdc++.h>
using namespace std;
const int maxn = 507;
const int INF = 0x3f3f3f3f;
int dp[maxn][maxn];
int a[maxn];
int n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, INF, sizeof(dp));
  for (int i = 0; i < n; i++) dp[i][i] = 1;
  for (int l = 2; l <= n; l++) {
    for (int i = 0; i + l - 1 < n; i++) {
      int j = i + l - 1;
      if (a[i] == a[j] && l > 2)
        dp[i][j] = dp[i + 1][j - 1];
      else if (a[i] == a[j])
        dp[i][j] = 1;
      for (int k = i; k < j; k++)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
