#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n;
int arr[N];
int mem[N][N];
int dp[N];
int solve(int l, int r) {
  if (l == r) return arr[l];
  int& res = mem[l][r];
  if (res != -1) return res;
  for (int k = l; k < r; k++) {
    int left = solve(l, k);
    int right = solve(k + 1, r);
    if (left && left == right) return res = left + 1;
  }
  return res = 0;
}
int calc(int i) {
  if (i >= n) return 0;
  int& r = dp[i];
  if (r != -1) return r;
  r = n;
  for (int j = i; j < n; j++) {
    if (solve(i, j)) {
      r = min(r, 1 + calc(j + 1));
    }
  }
  return r;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  memset(mem, -1, sizeof mem);
  memset(dp, -1, sizeof dp);
  cout << calc(0) << '\n';
  return 0;
}
