#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int input[n];
  for (int i = 0; i < n; i++) cin >> input[i];
  int dp[n][n];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) dp[i][i] = 1;
  for (int l = 2; l <= n; l++) {
    for (int i = 0; i < n - l + 1; i++) {
      int j = i + l - 1;
      int ans = 1 + dp[i + 1][j];
      if (input[i] == input[i + 1])
        ans = min(ans, 1 + (i + 2 <= j ? dp[i + 2][j] : 0));
      for (int x = i + 2; x <= j; x++) {
        if (input[i] == input[x])
          ans = min(ans, dp[i + 1][x - 1] + (x + 1 <= j ? dp[x + 1][j] : 0));
      }
      dp[i][j] = ans;
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
