#include <bits/stdc++.h>
using namespace std;
int a[510], dp[510][510];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, 0x3f, sizeof dp);
  for (int i = 0; i < n; i++) dp[i][i] = 1;
  for (int i = 0; i < n - 1; i++)
    if (a[i] == a[i + 1])
      dp[i][i + 1] = 1;
    else
      dp[i][i + 1] = 2;
  for (int l = 2; l < n; l++) {
    for (int i = 0, j = l; j < n; i++, j++) {
      dp[i][j] = dp[i][j - 1] + 1;
      for (int k = j - 1; k > i; k--) {
        if (a[j] != a[k]) continue;
        dp[i][j] = min(dp[i][j], dp[i][k - 1] + dp[k][j]);
      }
      if (a[i] == a[j]) dp[i][j] = min(dp[i + 1][j - 1], dp[i][j]);
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
