#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *a, **f;
  a = new int[n];
  f = new int *[n];
  for (register int i = 0; i < n; i++) {
    cin >> a[i];
    f[i] = new int[n];
    f[i][i] = 1;
    for (register int j = i + 1; j < n; j++) {
      f[i][j] = INT_MAX;
    }
  }
  for (register int i = 1; i < n; i++) {
    if (a[i - 1] == a[i]) {
      f[i - 1][i] = 1;
    } else {
      f[i - 1][i] = 2;
    }
  }
  int r;
  for (register int len = 2; len < n; len++) {
    for (register int l = 0; l + len < n; l++) {
      r = l + len;
      if (a[l] == a[r]) {
        f[l][r] = f[l + 1][r - 1];
      }
      for (register int i = l; i < r; i++) {
        f[l][r] = min(f[l][r], f[l][i] + f[i + 1][r]);
      }
    }
  }
  cout << f[0][n - 1] << endl;
  return 0;
}
