#include <bits/stdc++.h>
using namespace std;
int num[505];
int dp[505][505];
const int INF = 0x3f3f3f3f;
int dfs(int st, int ed) {
  if (st > ed) return 0;
  if (st == ed) {
    return 1;
  }
  if ((st + 1 == ed) && num[st] == num[ed]) {
    return 1;
  }
  if (dp[st][ed] != -1) {
    return dp[st][ed];
  }
  int md;
  int ans = 1 + dfs(st + 1, ed);
  for (md = ed; md > st; md--) {
    if (num[md] == num[st]) {
      if (st + 1 == md) {
        ans = min(ans, 1 + dfs(md + 1, ed));
      } else
        ans = min(ans, dfs(st + 1, md - 1) + dfs(md + 1, ed));
    }
  }
  return dp[st][ed] = ans;
}
int main(int argc, char *argv[]) {
  int n;
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
  }
  int ans = dfs(1, n);
  printf("%d\n", ans);
}
