#include <bits/stdc++.h>
using namespace std;
const int n = 600;
int N;
int arr[n];
int dp[n][n];
int go(int L, int R) {
  if (L > R) return 0;
  if (dp[L][R] != -1) return dp[L][R];
  int ret = N + 1;
  if (arr[L] == arr[R]) ret = go(L + 1, R - 1);
  for (int lr = L + 1; lr <= R; lr++) {
    ret = min(ret, go(L, lr - 1) + go(lr, R) + 1);
  }
  return dp[L][R] = ret;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", arr + i);
  }
  memset(dp, -1, sizeof dp);
  go(1, N);
  printf("%d", dp[1][N] + 1);
}
