#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 100005;
const int inf = 0x3f3f3f3f;
int dp[505][505], n;
int a[505];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 1; i <= n; i++) cin >> a[i], dp[i][i] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = i - 1; j >= 1; j--) {
      if (a[j] == a[i]) {
        if (j == i - 1) {
          dp[j][i] = 1;
          continue;
        }
        dp[j][i] = min(dp[j][i], dp[j + 1][i - 1]);
      }
      for (int k = j; k <= i; k++) {
        dp[j][i] = min(dp[j][k] + dp[k + 1][i], dp[j][i]);
      }
    }
  }
  cout << dp[1][n] << '\n';
  return 0;
}
