#include <bits/stdc++.h>
using namespace std;
int a[505], dp[505][505], w[505][505];
int main() {
  memset(dp, 63, sizeof(dp));
  int i, k, l, r, m, n;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i][i] = 1;
    w[i][i] = a[i];
  }
  for (k = 2; k <= n; k++) {
    for (l = 1; l + k - 1 <= n; l++) {
      r = l + k - 1;
      for (m = l; m < r; m++) {
        dp[l][r] = min(dp[l][r], dp[l][m] + dp[m + 1][r]);
        if (dp[l][m] == dp[m + 1][r] && dp[l][m] == 1 &&
            w[l][m] == w[m + 1][r]) {
          dp[l][r] = 1;
          w[l][r] = w[l][m] + 1;
        }
      }
    }
  }
  cout << dp[1][n] << endl;
  return 0;
}
