#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[510];
int dp[510][510];
int dfs(int l, int r) {
  if (dp[l][r] != -1) {
    return dp[l][r];
  }
  if (l > r) {
    return 0;
  }
  if (l == r) {
    return 1;
  }
  int mi = 1 + dfs(l + 1, r);
  if (a[l] == a[l + 1]) {
    mi = min(mi, 1 + dfs(l + 2, r));
  }
  for (int i = l + 2; i <= r; ++i) {
    if (a[i] == a[l]) {
      mi = min(mi, dfs(l + 1, i - 1) + dfs(i + 1, r));
    }
  }
  return dp[l][r] = mi;
}
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", dfs(0, n - 1));
  return 0;
}
