#include <bits/stdc++.h>
using namespace std;
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
const int N = 500;
int a[N];
int dp[N][N];
bool pal[N][N];
int main() {
  int n = ri();
  for (int i = 0; i < (n); i++) {
    a[i] = ri();
    dp[i][i] = 1;
    pal[i][i] = true;
  }
  for (int i = 0; i < (n - 1); i++) pal[i + 1][i] = true;
  for (int i = (n); --i >= (0);)
    for (int j = (i + 1); j < (n); j++)
      if (a[i] == a[j] && pal[i + 1][j - 1]) {
        dp[i][j] = 1;
        pal[i][j] = true;
      } else {
        dp[i][j] = n;
        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\n", dp[0][n - 1]);
}
