#include <bits/stdc++.h>
using namespace std;
int a[1005], dp[1005][1005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int l = n - 1; l >= 0; l--) {
    for (int r = l; r < n; r++) {
      dp[l][r] = -1;
      if (l == r) {
        dp[l][r] = a[l];
      } else {
        for (int k = l; k < r; k++) {
          if (dp[l][k] != -1 && dp[l][k] == dp[k + 1][r]) {
            dp[l][r] = dp[l][k] + 1;
          }
        }
      }
    }
  }
  vector<int> ans(n + 1, 1e9);
  ans[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (dp[i - j][i - 1] != -1) {
        ans[i] = min(ans[i], 1 + ans[i - j]);
      }
    }
  }
  cout << ans[n];
  return 0;
}
