#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long N = 505;
long long dp[N][N], n, a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 0; i < (n); ++i) cin >> a[i];
  for (long long i = 0; i < (N); ++i)
    for (long long j = 0; j < (N); ++j)
      if (i <= j) dp[i][j] = inf;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i; j < n; j++) {
      if (i == j) {
        dp[i][j] = 1;
        continue;
      }
      dp[i][j] = min(dp[i][j], dp[i + 1][j] + 1);
      if (a[i] == a[i + 1]) dp[i][j] = min(dp[i][j], dp[i + 2][j] + 1);
      for (int k = i + 2; k <= j; k++)
        if (a[k] == a[i])
          dp[i][j] = min(dp[i][j], dp[i + 1][k - 1] + dp[k + 1][j]);
    }
  }
  cout << dp[0][n - 1] << endl;
}
