#include <bits/stdc++.h>
using namespace std;
int dp[505][505], a[505];
int f(int l, int r) {
  if (l == r) return 1;
  if (l + 1 == r and a[l] != a[r]) return 2;
  if (l + 1 == r and a[l] == a[r]) return 1;
  if (dp[l][r] != -1) return dp[l][r];
  int res = 1e9;
  for (int(k) = (l); (k) <= (r - 1); (k)++)
    res = min(res, f(l, k) + f(k + 1, r));
  if (a[l] == a[r]) res = min(res, f(l + 1, r - 1));
  return dp[l][r] = res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int(i) = 0; (i) < (n); (i)++) scanf("%d", &a[i]);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", f(0, n - 1));
  return 0;
}
