#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9;
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 + 1, INF)),
      now(n, vector<int>(n + 1));
  for (int i = 0; i < n; i++) {
    dp[i][i + 1] = 1;
    now[i][i + 1] = a[i];
  }
  for (int len = 2; len <= n; len++) {
    for (int l = 0; l + len <= n; l++) {
      int r = l + len;
      for (int k = l; k < r; k++) {
        if (dp[l][k] == 1 && dp[k][r] == 1 && now[l][k] == now[k][r]) {
          dp[l][r] = 1;
          now[l][r] = now[l][k] + 1;
        } else {
          dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r]);
        }
      }
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}
