#include <bits/stdc++.h>
using namespace std;
const int N = 500;
int a[N + 10], dp[N + 10][N + 10];
int main() {
  int n;
  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] = 1 + (a[i] != a[i + 1]);
  for (int l = 3; l <= n; l++) {
    for (int i = 1; i + l - 1 <= n; i++) {
      int j = i + l - 1;
      dp[i][j] = 0x7fffffff;
      for (int k = i; k < j; 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", dp[1][n]);
  return 0;
}
