#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 5;
int dp[N][N];
int A[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (int i = 1; i <= n; i++) dp[i][i] = 1;
  for (int i = 1; i < n; i++) dp[i][i + 1] = 1 + (A[i] != A[i + 1]);
  for (int k = 3; k <= n; k++) {
    for (int i = 1; i + k - 1 <= n; i++) {
      int j = i + k - 1;
      int ans = n;
      for (int l = i; l < j; l++) {
        ans = min(ans, dp[i][l] + dp[l + 1][j]);
      }
      if (A[i] == A[j]) ans = min(ans, dp[i + 1][j - 1]);
      dp[i][j] = ans;
    }
  }
  cout << dp[1][n] << "\n";
  return 0;
}
