#include <bits/stdc++.h>
using namespace std;
int color[500 + 2];
int dp[500 + 2][500 + 2];
int main(int argc, const char* argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &color[i]);
  }
  for (int i = 1; i <= n; i++) {
    dp[i][i] = 1;
  }
  for (int h = 1; h < n; h++) {
    for (int i = 1; i <= n - h; i++) {
      int j = i + h;
      dp[i][j] = 1 + dp[i + 1][j];
      if (color[i] == color[i + 1]) {
        dp[i][j] = min(dp[i][j], 1 + dp[i + 2][j]);
      }
      for (int k = i + 2; k <= j; k++) {
        if (color[i] == color[k]) {
          dp[i][j] = min(dp[i][j], dp[i + 1][k - 1] + dp[k + 1][j]);
        }
      }
    }
  }
  printf("%d\n", dp[1][n]);
  return 0;
}
