#include <bits/stdc++.h>
using namespace std;
int n, a[505], dp[505][505];
inline int min(int x, int y) { return x < y ? x : y; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  memset(dp, 0x3f, sizeof dp);
  for (int i = 1; i <= n; ++i)
    dp[i][i] = 1, dp[i][i + 1] = a[i] == a[i + 1] ? 1 : 2;
  for (int len = 3; len <= n; ++len) {
    for (int i = 1; i <= n; ++i) {
      int j = i + len - 1;
      if (j > n) continue;
      if (a[i] == a[j]) {
        dp[i][j] = dp[i + 1][j - 1];
      }
      for (int k = i; k < j; ++k) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
      }
    }
  }
  printf("%d\n", dp[1][n]);
  return 0;
}
