#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int f[N][N], g[N][N], mr[N], ml[N];
int n, a[N];
int dfs(int l, int r) {
  if (g[l][r] == 1) return f[l][r] = 1;
  if (f[l][r] >= 1) return f[l][r];
  int &res = f[l][r] = 1000000000;
  for (int m = l; m < r; m++) {
    res = min(res, dfs(l, m) + dfs(m + 1, r));
  }
  int ll = l, rr = r;
  while (ll <= rr && a[ll] == a[rr]) {
    ll++;
    rr--;
    res = min(res, dfs(ll, rr));
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      int flag = 1;
      for (int k = i; k <= j; k++)
        if (a[k] != a[j - (k - i)]) flag = 0;
      g[i][j] = flag;
    }
  int ans = dfs(1, n);
  printf("%d\n", ans);
}
