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