#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const int N = 5e2 + 5;
int dp[N][N];
int a[N];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) dp[i][i] = 1;
  for (int len = 2; len <= n; len++) {
    for (int l = 1; l + len - 1 <= n; l++) {
      int r = l + len - 1;
      dp[l][r] = inf;
      if (a[l] == a[r]) {
        if (l + 1 >= r - 1)
          dp[l][r] = 1;
        else
          dp[l][r] = dp[l + 1][r - 1];
      }
      for (int i = l; i < r; i++) {
        dp[l][r] = min(dp[l][i] + dp[i + 1][r], dp[l][r]);
      }
    }
  }
  printf("%d\n", dp[1][n]);
  return 0;
}
