#include <bits/stdc++.h>
using namespace std;
int n, dp[501][501], a[501];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int leng = 1; leng <= n; leng++) {
    for (int i = 0, j = leng - 1; j < n; i++, j++) {
      if (leng == 1)
        dp[i][j] = 1;
      else {
        dp[i][j] = 1 + dp[i + 1][j];
        if (a[i] == a[i + 1]) dp[i][j] = min(dp[i][j], 1 + dp[i + 2][j]);
        for (int k = i + 2; k <= j; k++) {
          if (a[i] == a[k])
            dp[i][j] = min(dp[i][j], dp[i + 1][k - 1] + dp[k + 1][j]);
        }
      }
    }
  }
  cout << dp[0][n - 1];
}
