#include <bits/stdc++.h>
using namespace std;
const int INF = (-1u) / 2;
const long long int INF2 = (-1ull) / 2;
int a, b, i, dp[555][555], j, k, n, m, timer = 0, l, r, x, y, d[555][555];
int c[1011000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> c[i];
    dp[i][i] = 1;
  }
  for (l = 1; l < n; l++) {
    for (i = 0; i < n; i++) {
      if (i + l >= n) break;
      dp[i][i + l] = l + 1;
      for (j = i; j < i + l; j++) {
        dp[i][i + l] = min(dp[i][i + l], dp[i][j] + dp[j + 1][i + l]);
      }
      if (c[i] == c[i + l]) {
        if (l > 1)
          dp[i][i + l] = min(dp[i][i + l], dp[i + 1][i + l - 1]);
        else
          dp[i][i + l] = min(dp[i][i + l], 1);
      }
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
