#include <bits/stdc++.h>
using namespace std;
const int infi = 1000009;
int ar[509], n;
int dp[509][509];
int doit(int a, int b) {
  int i, j, k;
  if (a >= b) return 1;
  int ans = infi;
  if (dp[a][b] != -1) return dp[a][b];
  if (ar[a] == ar[b]) ans = min(ans, doit(a + 1, b - 1));
  for (i = a; i < b; i++) {
    ans = min(ans, doit(a, i) + doit(i + 1, b));
  }
  return dp[a][b] = ans;
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &ar[i]);
  for (i = 0; i <= n + 1; i++)
    for (j = 0; j <= n + 1; j++) dp[i][j] = -1;
  int ans = doit(1, n);
  printf("%d\n", ans);
  return 0;
}
