#include <bits/stdc++.h>
using namespace std;
const int INF = 1000;
int n, a[505], sum[505][505];
int judge(int l, int r) {
  for (int pl = l, pr = r; pl <= pr; pl++, pr--) {
    if (a[pl] != a[pr]) return 0;
  }
  return 1;
}
int dfs(int l, int r) {
  if (sum[l][r] != -1) return sum[l][r];
  if (judge(l, r) == 1 || l > r) {
    sum[l][r] = 0;
    return 0;
  }
  int ret = INF;
  for (int i = l; i <= r; i++) {
    if (a[l] == a[i]) {
      int t = dfs(l + 1, i - 1) + dfs(i + 1, r);
      if (i != r) t++;
      ret = min(ret, t);
    }
  }
  sum[l][r] = ret;
  return ret;
}
int main() {
  memset(sum, -1, sizeof(sum));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  int ans = dfs(1, n);
  printf("%d", ans + 1);
}
