#include <bits/stdc++.h>
using namespace std;
int dp[501][501];
vector<int> v(500);
long long palin(int i, int j) {
  if (j < i) return 1;
  long long ans = (int)1e9;
  for (int c = i; c < j; c++) ans = min(ans, palin(i, c) + palin(c + 1, j));
  return (v[i] == v[j]) ? min(ans, palin(i + 1, j - 1)) : ans;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = n; i > 0; i--)
    for (int j = 0; j < n + 1; j++) {
      if (j <= i)
        dp[i][j] = 1;
      else {
        int ans = (int)1e9;
        for (int c = i; c < j; c++) ans = min(ans, dp[i][c] + dp[c + 1][j]);
        dp[i][j] = (v[i - 1] == v[j - 1]) ? min(ans, dp[i + 1][j - 1]) : ans;
      }
    }
  cout << dp[1][n] << endl;
  return 0;
}
