#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int n;
int a[maxn], f[maxn][maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) f[i][i] = 1;
  for (int len = 2; len <= n; len++)
    for (int l = 1; l <= n - len + 1; l++) {
      int r = l + len - 1;
      f[l][r] = 1e9;
      for (int k = l; k < r; k++) f[l][r] = min(f[l][r], f[l][k] + f[k + 1][r]);
      if (a[l] == a[r])
        if (len == 2)
          f[l][r] = 1;
        else {
          f[l][r] = min(f[l][r], f[l + 1][r - 1]);
        }
    }
  printf("%d", f[1][n]);
  return 0;
}
