#include <bits/stdc++.h>
using namespace std;
int ns[505];
int dp[505][505];
int dp2[505];
int aux[505][505];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ns[i];
  }
  for (int i = 0; i < n; i++) {
    dp[i][i] = 1;
    aux[i][i] = ns[i];
  }
  for (int l = 2; l < n + 1; l++) {
    for (int i = 0; i < n; i++) {
      int j = i + l - 1;
      for (int k = i; k < j + 1; k++) {
        if (dp[i][k] && dp[k + 1][j] && aux[i][k] == aux[k + 1][j]) {
          dp[i][j] = 1;
          aux[i][j] = aux[i][k] + 1;
        }
      }
    }
  }
  dp2[0] = 1;
  for (int i = 1; i < n; i++) {
    dp2[i] = INT_MAX;
    if (dp[0][i]) {
      dp2[i] = 1;
    }
    for (int j = 0; j < i + 1; j++) {
      if (dp[j + 1][i]) {
        dp2[i] = min(dp2[i], dp2[j] + 1);
      }
    }
  }
  cout << dp2[n - 1];
}
