#include <bits/stdc++.h>
using namespace std;
const int Maxn = 510;
const int INF = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, c[Maxn];
int dp[Maxn][Maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 0; i < n + 5; i++)
    for (int j = 0; j < n + 5; j++) dp[i][j] = 1e9;
  dp[1][1] = 1;
  dp[1][0] = 0;
  dp[0][1] = 0;
  dp[0][0] = 0;
  for (int i = 2; i <= n; i++)
    for (int j = i; j >= 1; j--) {
      if (i == j)
        dp[i][j] = 1;
      else if (c[i] == c[j] && i == j + 1)
        dp[i][j] = 1;
      else if (c[i] == c[j])
        dp[i][j] = dp[i - 1][j + 1];
      for (int k = i; k > j; k--)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k - 1][j]);
    }
  cout << dp[n][1] << endl;
  return 0;
}
