#include <bits/stdc++.h>
using namespace std;
int a[1000];
const int oo = 100000000;
int dp[550][550];
int go(int x, int y) {
  if (x == y) return 1;
  if (x == y - 1 && a[x] == a[y]) return 1;
  if (x == y - 1 && a[x] != a[y]) return 2;
  if (dp[x][y] != -1) return dp[x][y];
  int ans = oo;
  for (int i = x; i <= y - 1; i++) ans = min(ans, go(x, i) + go(i + 1, y));
  if (a[x] == a[y]) ans = min(ans, go(x + 1, y - 1));
  return dp[x][y] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  memset(dp, -1, sizeof(dp));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << go(0, n - 1);
  return 0;
}
