#include <bits/stdc++.h>
using namespace std;
inline void ReadInt(int &num) {
  num = 0;
  int f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = num * 10 + (c - '0');
    c = getchar();
  }
  num = num * f;
  return;
}
inline void ReadLong(long long &num) {
  num = 0;
  int f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = num * 10 + (c - '0');
    c = getchar();
  }
  num = num * f;
  return;
}
int n;
int a[505];
int dp[505][505];
int main() {
  ReadInt(n);
  for (int i = 0; i < n; i++) ReadInt(a[i]);
  for (int l = 1; l <= n; l++) {
    for (int i = 0; i + l <= n; i++) {
      int s = i, t = i + l - 1;
      if (l == 1)
        dp[s][t] = 1;
      else {
        dp[s][t] = n;
        for (int j = s; j < t; j++)
          dp[s][t] = min(dp[s][t], dp[s][j] + dp[j + 1][t]);
        if (a[s] == a[t])
          dp[s][t] = min(dp[s][t], l == 2 ? 1 : dp[s + 1][t - 1]);
      }
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
