#include <bits/stdc++.h>
using namespace std;
const int N = 509;
const int inf = (int)2e9;
const int mod = (int)1e9 + 7;
const double eps = 1e-10;
int a[N];
int dp[N][N];
int get(int l, int r) {
  int &res = dp[l][r];
  if (l >= r) return 1;
  if (res) return res;
  res = inf;
  if (a[l] == a[r]) res = get(l + 1, r - 1);
  for (int i = l; i < r; i++) res = min(res, get(l, i) + get(i + 1, r));
  return res;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << get(0, n - 1) << endl;
  return 0;
}
