#include <bits/stdc++.h>
using namespace std;
int n, i, j, len;
int a[512], dp[512][512];
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++) dp[i][i + 1] = (a[i] == a[i + 1]) ? 1 : 2;
  for (int len = 3; len <= n; len++)
    for (int i = 1; i <= n - len + 1; i++) {
      j = i + len - 1;
      dp[i][j] = min(1 + dp[i + 1][j], 1 + dp[i][j - 1]);
      for (int k = i + 1; k < j; k++)
        if (a[i] == a[k]) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
      if (a[i] == a[j]) dp[i][j] = min(dp[i][j], dp[i + 1][j - 1]);
    }
  printf("%d\n", dp[1][n]);
  return 0;
}
