#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, m, dp[N][N], c[N];
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (i = 1; i <= n; i++) dp[i][i] = 1;
  for (i = 1; i < n; i++)
    if (c[i] == c[i + 1])
      dp[i][i + 1] = 1;
    else
      dp[i][i + 1] = 2;
  for (int len = 3; len <= n; len++) {
    for (int l = 1; l <= n - len + 1; l++) {
      int r = l + len - 1;
      dp[l][r] = N;
      if (c[r] == c[l])
        dp[l][r] =
            ((dp[l][r] < dp[l + 1][r - 1]) ? dp[l][r] : dp[l + 1][r - 1]);
      for (int k = l; k <= r - 1; k++) {
        dp[l][r] =
            ((dp[l][r] < dp[l][k] + dp[k + 1][r]) ? dp[l][r]
                                                  : dp[l][k] + dp[k + 1][r]);
      }
    }
  }
  printf("%d\n", dp[1][n]);
  return 0;
}
