#include <bits/stdc++.h>
using namespace std;
int dp[501][501];
int a[501];
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 i = 1; i < n; i++)
    if (a[i] == a[i + 1])
      dp[i][i + 1] = 1;
    else
      dp[i][i + 1] = 2;
  for (int k = 3; k <= n; k++)
    for (int l = 1;; l++) {
      int r = l + k - 1;
      if (r > n) break;
      dp[l][r] = 2000000000;
      if (a[l] == a[r]) dp[l][r] = dp[l + 1][r - 1];
      for (int mid = l; mid < r; mid++)
        dp[l][r] = min(dp[l][r], dp[l][mid] + dp[mid + 1][r]);
    }
  printf("%d", dp[1][n]);
  return 0;
}
