#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n], dp[550][550] = {};
  for (long long i = 0; i < n; i++) cin >> arr[i];
  for (long long size = 1; size <= n; size++) {
    for (long long r = size - 1; r < n; r++) {
      long long l = r - size + 1;
      if (r == l)
        dp[l][r] = 1;
      else if (r == l + 1) {
        if (arr[l] == arr[r])
          dp[l][r] = 1;
        else
          dp[l][r] = 2;
      } else {
        dp[l][r] = 1 + dp[l + 1][r];
        if (arr[l] == arr[l + 1]) dp[l][r] = min(dp[l][r], 1 + dp[l + 2][r]);
        for (long long k = l + 2; k <= r; k++) {
          if (arr[l] == arr[k])
            dp[l][r] = min(dp[l][r], dp[l + 1][k - 1] + dp[k + 1][r]);
        }
      }
    }
  }
  cout << dp[0][n - 1];
  return 0;
}
