#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
template <class T>
inline bool Min(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
inline bool Max(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
inline int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
inline void pi(int a) { printf("%d", a); }
inline ll nl() {
  ll a;
  scanf("%lld", &a);
  return a;
}
inline void pl(ll a) { printf("%lld", a); }
inline double nd() {
  double a;
  scanf("%lf", &a);
  return a;
}
inline void pd(double a) { printf("%.10lf", a); }
inline void sp() { putchar(' '); }
inline void en() { putchar('\n'); }
const int N = 510;
int dp[N][N];
void solve() {
  int n = ni();
  vector<int> xs(n);
  for (int i = 0; i < (int)(n); ++i) xs[i] = ni();
  for (int i = 0; i < (int)(n); ++i) dp[i][i] = 1;
  for (int len = 2; len <= n; len++) {
    for (int i = 0; i < n; i++) {
      int j = i + len - 1;
      if (j >= n) break;
      dp[i][j] = 2 + dp[i + 1][j - 1];
      for (int t = i; t < j; t++) {
        Min(dp[i][j], dp[i][t] + dp[t + 1][j]);
      }
      if (xs[i] == xs[j] && len > 2) Min(dp[i][j], dp[i + 1][j - 1]);
      if (xs[i] == xs[j] && len == 2) dp[i][j] = 1;
    }
  }
  pi(dp[0][n - 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
