#include <bits/stdc++.h>
using namespace std;
int const N = 555;
int n, a[N], dp[N][N];
int f(int i, int j) {
  if (i > j) return 0;
  if (j == i) return 1;
  int &ret = dp[i][j];
  if (ret != -1) return ret;
  ret = 1e9;
  ret = 1 + f(i + 1, j);
  if (a[i] == a[i + 1]) {
    ret = min(ret, 1 + f(i + 2, j));
  }
  for (int id = i + 2; id <= j; id++) {
    if (a[i] == a[id]) {
      ret = min(ret, f(i + 1, id - 1) + f(id + 1, j));
    }
  }
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof dp);
  cout << f(0, n - 1);
}
