#include <bits/stdc++.h>
using namespace std;
const int INF = 10000;
int dp[501][501], n;
bool vis[501][501];
int a[501];
void calc(int l, int r) {
  if (vis[l][r]) return;
  vis[l][r] = true;
  if (l == r) {
    dp[l][r] = 1;
    return;
  }
  if (l + 1 == r && a[l] == a[r]) {
    dp[l][r] = 1;
    return;
  }
  if (a[l] == a[r]) {
    calc(l + 1, r - 1);
    dp[l][r] = dp[l + 1][r - 1];
  }
  for (int i = l; i < r; i++) {
    calc(l, i);
    calc(i + 1, r);
    dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r]);
  }
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(dp, INF, sizeof(dp));
  memset(vis, false, sizeof(vis));
  calc(1, n);
  printf("%d\n", dp[1][n]);
  return 0;
}
