#include <bits/stdc++.h>
using namespace std;
const int M = 510;
int n, a[M];
int dp[M][M];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  memset(dp, 88, sizeof dp);
  for (int i = 0; i <= n; ++i) {
    for (int j = 1; j + i - 1 <= n; ++j) {
      if (i <= 1)
        dp[i][j] = 1;
      else {
        if (a[j] == a[i + j - 1]) dp[i][j] = dp[i - 2][j + 1];
        for (int k = 1; k < i; ++k)
          dp[i][j] = min(dp[i][j], dp[k][j] + dp[i - k][j + k]);
      }
    }
  }
  printf("%d", dp[n][1]);
}
