#include <bits/stdc++.h>
using namespace std;
int dp[523][523];
int a[523];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int d = 0; d < n; d++) {
    for (int i = 0; i + d < n; i++) {
      if (d == 0)
        dp[i][i] = 1;
      else {
        int j = i + d;
        dp[i][j] = 1 + dp[i + 1][j];
        for (int k = i + 2; k <= j; k++)
          if (a[i] == a[k])
            dp[i][j] = min(dp[i][j], dp[i + 1][k - 1] + dp[k + 1][j]);
        if (a[i] == a[i + 1]) dp[i][j] = min(dp[i][j], 1 + dp[i + 2][j]);
      }
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
