#include <bits/stdc++.h>
using namespace std;
int dp[501][501];
int dp2[501];
int n = 0;
int arr[501];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) dp[i][j] = -1;
    dp[i][i] = arr[i];
  }
  for (int len = 1; len < n; len++) {
    for (int i = 0; i + len < n; i++) {
      int j = i + len;
      for (int mid = i; mid < j; mid++) {
        if (dp[i][mid] != -1 && dp[i][mid] == dp[mid + 1][j]) {
          dp[i][j] = dp[i][mid] + 1;
          break;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (dp[0][i] != -1)
      dp2[i] = 1;
    else
      dp2[i] = INT_MAX;
  }
  for (int i = 0; i < n; i++) {
    if (dp2[i] != INT_MAX) {
      for (int j = i + 1; j < n; j++)
        if (dp[i + 1][j] != -1) {
          dp2[j] = min(dp2[j], dp2[i] + 1);
        }
    }
  }
  cout << dp2[n - 1];
  return 0;
}
