#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[505];
long long cache[505][505];
long long solve(long long i, long long j) {
  if (i > j) {
    return 0;
  }
  if (cache[i][j] != -1) {
    return cache[i][j];
  }
  long long &ans = cache[i][j];
  if (i == j) {
    return ans = 1;
  }
  ans = 1 + solve(i + 1, j);
  for (long long k = i + 2; k <= j; k++) {
    if (a[i] == a[k]) {
      ans = min(ans, solve(i + 1, k - 1) + solve(k + 1, j));
    }
  }
  if (a[i] == a[i + 1]) {
    ans = min(ans, 1 + solve(i + 2, j));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  memset(cache, -1, sizeof(cache));
  cout << solve(1, n) << '\n';
  return 0;
}
