#include <bits/stdc++.h>
const static int INF = 0x3f3f3f3f;
static inline void setio(void);
int a[501];
int memo[501][501];
int main(void) {
  setio();
  memset(memo, 0xff, sizeof(memo));
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  std::function<int(const int&, const int&)> go = [&](const int& rl,
                                                      const int& rr) {
    if (rl >= rr) return 1;
    if (memo[rl][rr] != -1) return memo[rl][rr];
    int ret = INF;
    ret = std::min(ret, 1 + go(rl + 1, rr));
    ret = std::min(ret, 1 + go(rl, rr - 1));
    if (a[rl] == a[rr]) {
      ret = std::min(ret, go(rl + 1, rr - 1));
    }
    for (int i = rl + 1; i < rr; ++i) {
      if (a[i] == a[rr]) ret = std::min(ret, go(rl, i - 1) + go(i + 1, rr - 1));
    }
    return memo[rl][rr] = ret;
  };
  std::cout << go(0, n - 1) << "\n";
  return 0;
}
static inline void setio(void) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(10);
  std::cout << std::fixed;
}
