#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 505;
int DP[N][N], A[N];
int solve(int x, int y) {
  if (DP[x][y]) return DP[x][y];
  if (x == y) return (DP[x][y] = 1);
  DP[x][y] = 1005;
  if (A[x] == A[y]) {
    if (x + 1 == y) return (DP[x][y] = 1);
    DP[x][y] = solve(x + 1, y - 1);
  }
  for (int i = x; i < y; i++) {
    DP[x][y] = min(DP[x][y], solve(x, i) + solve(i + 1, y));
  }
  return DP[x][y];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  printf("%d\n", solve(1, n));
  return 0;
}
