#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int mxN = 505;
vector<vector<int>> dp(mxN, vector<int>(mxN, inf));
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i; j < n; j++) {
      if (i == j) {
        dp[i][j] = 1;
        continue;
      }
      if (j == i + 1) {
        dp[i][j] = (v[i] == v[j] ? 1 : 2);
        continue;
      }
      for (int k = i; k < j; k++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
      }
      if (v[i] == v[j]) {
        dp[i][j] = min(dp[i][j], dp[i + 1][j - 1]);
      }
    }
  }
  cout << dp[0][n - 1] << '\n';
}
