#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int dp[509][509], arr[100009];
int rec(int l, int r) {
  if (l >= r) return 1;
  int& ret = dp[l][r];
  if (dp[l][r] != -1) return ret;
  ret = 1000000007;
  if (arr[l] == arr[r]) ret = rec(l + 1, r - 1);
  for (int i = l; i < r; i++) umin(ret, rec(l, i) + rec(i + 1, r));
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int a;
  cin >> a;
  for (int i = 1; i <= a; i++) cin >> arr[i];
  cout << rec(1, a) << endl;
  return 0;
}
