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