#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    sum = sum * 10 + (c ^ 48);
    c = getchar();
  }
  return sum;
}
int const maxn = 505;
int n, a[maxn], f[maxn][maxn];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read(), f[i][i] = 1;
  for (int i = n; i >= 1; i--)
    for (int j = i + 1; j <= n; j++) {
      f[i][j] = 1e8;
      for (int k = i; k < j; k++) f[i][j] = min(f[i][j], f[i][k] + f[k + 1][j]);
      if (a[i] == a[j]) {
        if (i + 1 > j - 1)
          f[i][j] = min(f[i][j], 1);
        else
          f[i][j] = min(f[i][j], f[i + 1][j - 1]);
      }
    }
  cout << f[1][n] << endl;
  return 0;
}
