#include <bits/stdc++.h>
using namespace std;
int a[501];
int dp[501][501];
int solve(int i, int j) {
  if (dp[i][j] != -1) return dp[i][j];
  if (i > j) {
    dp[i][j] = 0;
    return 0;
  }
  if (i == j) {
    dp[i][j] = 1;
    return 1;
  }
  if (j - i == 1) {
    if (a[j] == a[i]) {
      dp[i][j] = 1;
      return 1;
    } else {
      dp[i][j] = 2;
      return 2;
    }
  }
  int ans = 1 + solve(i + 1, j);
  for (int i1 = j; i1 > i; i1--) {
    if (a[i1] == a[i]) {
      if (i1 != i + 1)
        ans = min(ans, solve(i + 1, i1 - 1) + solve(i1 + 1, j));
      else
        ans = min(ans, 1 + solve(i1 + 1, j));
    }
  }
  dp[i][j] = ans;
  return ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << solve(0, n - 1);
  return 0;
}
