#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
vector<int> v;
int memo[555][555];
int n;
bool chk(vector<int> &v) {
  int st = 0, en = int((v).size()) - 1;
  while (st < en) {
    if (v[st] != v[en]) return false;
    st++;
    en--;
  }
  return true;
}
int rec(int l, int r) {
  if (l >= r) return 1;
  int res = 1000000000;
  int &re = memo[l][r];
  if (re != -1) return re;
  if (v[l] == v[r]) res = min(res, rec(l + 1, r - 1));
  for (int i = l; i < r; i++) res = min(res, rec(l, i) + rec(i + 1, r));
  return re = res;
}
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(memo, -1, sizeof(memo));
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int res = rec(0, n - 1);
  cout << res << endl;
  return 0;
}
