#include <bits/stdc++.h>
using namespace std;
long long n, dp[505][505], a[505], tmp;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long j = 0; j <= n - 1; j++) {
    for (long long i = 1; i <= n; i++) {
      if (i + j > n) continue;
      tmp = dp[i + 1][i + j] + 1;
      for (long long k = 0; k <= j; k++)
        if (a[i] == a[i + k])
          tmp = min(tmp, max((long long)1, dp[i + 1][i + k - 1]) +
                             dp[i + k + 1][i + j]);
      dp[i][i + j] = tmp;
    }
  }
  cout << dp[1][n] << endl;
}
