#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, a[N], dp[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  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 len = 2; len <= n; ++len) {
    for (int l = 1; l + len - 1 <= n; ++l) {
      int r = l + len - 1;
      if (a[l] == a[r])
        dp[l][r] = max(dp[l + 1][r - 1], 1);
      else
        dp[l][r] = (int)1e9;
      for (int k = l + 1; k <= r; ++k)
        dp[l][r] = min(dp[l][r], dp[l][k - 1] + dp[k][r]);
    }
  }
  cout << dp[1][n];
}
