#include <bits/stdc++.h>
using namespace std;
const int N = 1010, INF = 0x3f3f3f3f;
int n, a[N], f[N][N];
int main() {
  scanf("%d", &n);
  memset(f, 0x3f, sizeof(f));
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), f[i][i] = f[i][i - 1] = 1;
  for (int l = 1; l <= n; l++)
    for (int i = 1; i <= n - l; i++) {
      int j = i + l;
      if (a[i] == a[j]) f[i][j] = f[i + 1][j - 1];
      for (int k = i; k <= j; k++)
        f[i][j] =
            (f[i][j] < f[i][k] + f[k + 1][j] ? f[i][j] : f[i][k] + f[k + 1][j]);
    }
  printf("%d\n", f[1][n]);
  return 0;
}
