#include <bits/stdc++.h>
using namespace std;
int n;
int dp[500][500];
int a[500];
bool ispalin(int l, int r) {
  while (l < r) {
    if (a[l] != a[r]) return false;
    l++;
    r--;
  }
  return true;
}
int compute(int l, int r) {
  if (l > r || l < 0 || r >= n) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  if (ispalin(l, r)) {
    dp[l][r] = 1;
    return 1;
  }
  int ans = compute(l + 1, r) + 1;
  for (__typeof(r + 1) i = (l + 1); i != (r + 1); i++) {
    if (a[i] == a[l]) {
      int t1 = compute(l + 1, i - 1);
      if (t1 == 0) t1 = 1;
      t1 += compute(i + 1, r);
      ans = min(t1, ans);
    }
  }
  dp[l][r] = ans;
  return ans;
}
int main() {
  cin >> n;
  for (__typeof(n) i = (0); i != (n); i++) cin >> a[i];
  for (__typeof(n) i = (0); i != (n); i++)
    for (__typeof(n) j = (0); j != (n); j++) dp[i][j] = -1;
  cout << compute(0, n - 1);
  return 0;
}
