#include <bits/stdc++.h>
using namespace std;
int n;
int a[510];
int dp[510][510];
int solve(int l, int r) {
  if (l > r) return 0;
  if (l == r) return 1;
  int& ans = dp[l][r];
  if (ans != -1) return ans;
  ans = solve(l + 1, r) + 1;
  int k = l + 1;
  if (a[l] == a[l + 1]) {
    ans = min(ans, solve(l + 2, r) + 1);
    k++;
  }
  for (; k <= r; ++k)
    if (a[l] == a[k]) {
      ans = min(ans, solve(l + 1, k - 1) + solve(k + 1, r));
    }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << solve(0, n - 1);
  return 0;
}
