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