#include <bits/stdc++.h>
using namespace std;
int n, c[502], dp[502][502];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    dp[i][i] = 1;
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j <= n - i; ++j) {
      if (c[j] == c[j + i - 1]) {
        if (i > 2)
          dp[j][j + i - 1] = dp[j + 1][j + i - 2];
        else
          dp[j][j + i - 1] = 1;
      } else {
        dp[j][j + i - 1] = 1e9;
      }
      for (int k = j; k < j + i - 1; ++k) {
        dp[j][j + i - 1] =
            min(dp[j][j + i - 1], dp[j][k] + dp[k + 1][j + i - 1]);
      }
    }
  }
  cout << dp[0][n - 1] << endl;
}
