#include <bits/stdc++.h>
using namespace std;
long long a[200000], b[1000][1000];
long long are(long long i, long long j) {
  long long x = 0;
  if (b[i][j]) return b[i][j];
  if (i > j)
    x = 0;
  else if (i == j) {
    x = 1;
  } else {
    x = 1 + are(i + 1, j);
    for (long long q = i + 2; q <= j; q++) {
      if (a[q] == a[i]) {
        x = min(x, are(i + 1, q - 1) + are(q + 1, j));
      }
    }
    if (a[i] == a[i + 1]) x = min(1 + are(i + 2, j), x);
  }
  b[i][j] = x;
  return x;
}
int32_t main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  cout << are(0, n - 1);
}
