#include <bits/stdc++.h>
using namespace std;
const int M = 550;
int a[M], dp[M][M], n;
int func(int l, int r) {
  if (l >= r) return 1;
  if (dp[l][r]) return dp[l][r];
  int v = r - l + 1;
  if (a[l] == a[r]) {
    v = min(v, func(l + 1, r - 1));
  }
  for (int i = l; i < r; i++) v = min(v, func(l, i) + func(i + 1, r));
  dp[l][r] = v;
  return v;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = func(1, n);
  cout << ans << endl;
  return 0;
}
