#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 555;
const int inf = 1e9;
int n, a[maxn];
int dp[maxn][maxn];
int go(int l, int r) {
  if (l > r) return inf;
  if (l == r) return dp[l][r] = 1;
  if (l + 1 == r) {
    if (a[l] == a[r]) return dp[l][r] = 1;
    return dp[l][r] = 2;
  }
  if (dp[l][r] != -1) return dp[l][r];
  dp[l][r] = 1 + go(l + 1, r);
  for (int k = l + 1; k <= r; k++) {
    if (a[l] == a[k]) {
      int left = 1;
      if (l + 1 <= k - 1) left = go(l + 1, k - 1);
      int right = 0;
      if (k + 1 <= r) right = go(k + 1, r);
      dp[l][r] = min(dp[l][r], left + right);
    }
  }
  return dp[l][r];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof dp);
  go(0, n - 1);
  out(dp[0][n - 1]);
  return 0;
}
