#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static const int L = 233333;
  static char sxd[L], *sss = sxd, *ttt = sxd;
  if (sss == ttt) {
    ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
    if (sss == ttt) {
      return EOF;
    }
  }
  return *sss++;
}
inline char readchar() {
  char c = gc();
  for (; !isalpha(c); c = gc())
    ;
  return c;
}
template <class T>
inline bool read(T& x) {
  bool flg = false;
  char c = gc();
  x = 0;
  for (; !isdigit(c); c = gc()) {
    if (c == '-') {
      flg = true;
    } else if (c == EOF) {
      return false;
    }
  }
  for (; isdigit(c); c = gc()) {
    x = (x << 1) + (x << 3) + (c ^ 48);
  }
  if (flg) {
    x = -x;
  }
  return true;
}
const int maxn = 505;
const int inf = 0x3f3f3f3f;
int dp[maxn][maxn];
int c[maxn];
int main() {
  int n;
  read(n);
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 1; i <= n; ++i) {
    read(c[i]);
    dp[i][i] = 1;
    dp[i][i - 1] = 1;
  }
  for (int r = 1; r <= n; ++r) {
    for (int l = r - 1; l; --l) {
      if (c[l] == c[r]) {
        dp[l][r] = dp[l + 1][r - 1];
      }
      for (int k = l; k < r; ++k) {
        dp[l][r] = min(dp[l][k] + dp[k + 1][r], dp[l][r]);
      }
    }
  }
  printf("%d\n", dp[1][n]);
  return 0;
}
