#include <bits/stdc++.h>
using namespace std;
int n, a[510], memo[510][510];
int solve(int x, int y) {
  if (x > y) return 0;
  if (x == y) return 1;
  if (memo[x][y] != -1) return memo[x][y];
  int ret = 1e9;
  ret = min(ret, solve(x + 1, y) + 1);
  if (a[x] == a[x + 1]) ret = min(ret, solve(x + 2, y) + 1);
  for (int i = x + 2; i <= y; i++) {
    if (a[x] == a[i]) {
      ret = min(ret, solve(x + 1, i - 1) + solve(i + 1, y));
    }
  }
  return memo[x][y] = ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  memset(memo, -1, sizeof(memo));
  printf("%d\n", solve(0, n - 1));
  return 0;
}
