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