#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int dp[maxn][maxn], a[maxn];
int solve(int L, int R) {
  if (L >= R) return 1;
  if (dp[L][R] != -1) return dp[L][R];
  dp[L][R] = 1000000;
  if (a[L] == a[R]) dp[L][R] = solve(L + 1, R - 1);
  for (int i = L; i < R; i++)
    dp[L][R] = min(dp[L][R], solve(L, i) + solve(i + 1, R));
  return dp[L][R];
}
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    memset(dp, -1, sizeof(dp));
    dp[1][n] = solve(1, n);
    cout << dp[1][n] << "\n";
  }
  return 0;
}
