#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const long long SZ = 510, SSZ = 10 * SZ, APB = 20, INF = 0x7FFFFFFF,
                mod = 1000000007;
long long n, arr[SZ], dp[SZ][SZ];
void release() {}
void init() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  for (int i = 1; i <= n; ++i) dp[i][i] = 1;
  for (int len = 2; len <= n; ++len) {
    for (int i = 1; i <= n; ++i) {
      int j = i + len - 1;
      if (j > n) continue;
      dp[i][j] = INF;
      if (arr[i] == arr[j]) {
        if (len == 2)
          dp[i][j] = 1;
        else
          dp[i][j] = dp[i + 1][j - 1];
      }
      for (int k = i; k < j; ++k)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
    }
  }
  cout << dp[1][n] << endl;
}
void work() {}
int main() {
  std::ios::sync_with_stdio(0);
  long long casenum;
  {
    init();
    work();
    release();
  }
  return 0;
}
