#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<vector<int> > dp(n, vector<int>(n, n));
  for (int i = 0; i < n; ++i) {
    dp[i][i] = 1;
  }
  for (int len = 2; len <= n; ++len) {
    for (int i = 0; i + len <= n; ++i) {
      int j = i + len - 1;
      for (int x = i; x < j; ++x) {
        dp[i][j] = min(dp[i][j], dp[i][x] + dp[x + 1][j]);
      }
      if (a[i] == a[j]) {
        if (i == j - 1) {
          dp[i][j] = 1;
        } else {
          dp[i][j] = min(dp[i][j], dp[i + 1][j - 1]);
        }
      }
    }
  }
  cout << dp[0][n - 1] << "\n";
}
