#include <bits/stdc++.h>
using namespace std;
int dp[505][505] = {0}, arr[500], n;
int check(int i, int j) {
  if (dp[i][j] != 0) return dp[i][j];
  if (i > j) return 0;
  if (i == j) {
    dp[i][j] = 1;
    return 1;
  }
  int a = 1 + check(i + 1, j);
  int m = 1e9, it;
  for (it = i + 2; it <= j; it++) {
    if (arr[i] == arr[it]) {
      if (m > check(i + 1, it - 1) + check(it + 1, j)) {
        m = check(i + 1, it - 1) + check(it + 1, j);
      }
    }
  }
  int c = 1e9;
  if (arr[i] == arr[i + 1]) c = 1 + check(i + 2, j);
  dp[i][j] = min(min(c, a), m);
  return dp[i][j];
}
int main() {
  cin >> n;
  int i, j, k, l;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int len;
  for (len = 1; len <= n; len++) {
    for (i = 0, j = len - 1; j < n; j++, i++) {
      if (len == 1) {
        dp[i][j] = 1;
        continue;
      }
      dp[i][j] = 1 + dp[i + 1][j];
      if (arr[i] == arr[i + 1]) {
        dp[i][j] = min(dp[i][j], 1 + dp[i + 2][j]);
      }
      for (k = i + 2; k <= j; k++) {
        if (arr[i] == arr[k]) {
          dp[i][j] = min(dp[i][j], dp[i + 1][k - 1] + dp[k + 1][j]);
        }
      }
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
