#include <bits/stdc++.h>
using namespace std;
int a[600];
const int INF = 9999;
int dp[555][555];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i <= n; i++) {
    dp[i][i] = 1;
    if (a[i] == a[i + 1])
      dp[i][i + 1] = 1;
    else
      dp[i][i + 1] = 2;
    for (int j = i + 2; j <= n; j++) dp[i][j] = INF;
  }
  for (int len = 2; len < n; len++) {
    for (int i = 0; i + len < n; i++) {
      int mincost = len + 1;
      int j = i + len;
      if (a[i] == a[j]) {
        dp[i][j] = min(dp[i + 1][j - 1], dp[i][j]);
      }
      for (int k = i; k < j; k++) {
        int num = dp[i][k] + dp[k + 1][j];
        mincost = min(mincost, num);
      }
      dp[i][j] = min(dp[i][j], mincost);
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
