#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int a[505];
  int dp[505][505];
  int dp2[505] = {111111111};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i; j < n; j++) {
      if (i == j) {
        dp[i][j] = a[i];
      } else {
        dp[i][j] = -1;
        for (int ii = i; ii < j; ii++) {
          if (dp[i][ii] != -1 && dp[i][ii] == dp[ii + 1][j]) {
            dp[i][j] = dp[i][ii] + 1;
            break;
          }
        }
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    dp2[i] = 1e9;
  }
  dp2[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (dp[i][j] != -1) {
        dp2[j + 1] = min(dp2[j + 1], dp2[i] + 1);
      }
    }
  }
  cout << dp2[n] << endl;
}
