#include <bits/stdc++.h>
using namespace std;
int a[505];
int d[505][505];
int solve(int l, int r) {
  if (d[l][r] == -1) {
    if (l >= r)
      d[l][r] = 1;
    else {
      if (a[l] == a[r])
        d[l][r] = solve(l + 1, r - 1);
      else
        d[l][r] = 1000;
      for (int i = l; i < r; i++)
        d[l][r] = min(d[l][r], solve(l, i) + solve(i + 1, r));
    }
  }
  return d[l][r];
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  fill(&d[0][0], &d[505][0], -1);
  cout << solve(0, n - 1) << endl;
}
