#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 10;
const int inf = 0x3f3f3f3f;
int a[maxn];
int dp[maxn][maxn];
int n;
int getAns(int l, int r) {
  if (l > r) return 0;
  if (l == r) return 1;
  if (dp[l][r] != -1) return dp[l][r];
  int tem = inf;
  tem = min(tem, 1 + getAns(l + 1, r));
  if (a[l] == a[l + 1]) tem = min(tem, getAns(l + 2, r) + 1);
  for (int i = l + 2; i <= r; i++) {
    if (a[i] == a[l]) tem = min(tem, getAns(l + 1, i - 1) + getAns(i + 1, r));
  }
  return dp[l][r] = tem;
}
int solve() {
  memset(dp, -1, sizeof dp);
  int ans = getAns(0, n - 1);
  return ans;
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int ans = solve();
    printf("%d\n", ans);
  }
  return 0;
}
