#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-6;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * (b / (gcd(a, b))); }
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline long long toLL(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
using namespace std;
int n;
int arr[501];
int DP[501][501];
int solve(int i, int j) {
  if (i > j) return 1;
  if (i == j) return 1;
  int &ret = DP[i][j];
  if (ret != -1) return ret;
  ret = j - i + 1;
  if (arr[i] == arr[j]) ret = solve(i + 1, j - 1);
  for (int k = i; k < j; k++) ret = min(ret, solve(i, k) + solve(k + 1, j));
  DP[i][j] = ret;
  return ret;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n;
  memset(DP, -1, sizeof(DP));
  for (int i = 0; i < (int)n; i++) cin >> arr[i];
  cout << solve(0, n - 1);
}
