#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, a[N], f[N][N], ans, w[N][N];
int main() {
  scanf("%d", &n);
  memset(f, 0x3f, sizeof(f));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    f[i][i] = 1;
    w[i][i] = a[i];
  }
  for (int i = 2; i <= n; i++) {
    for (int l = 1; l + i - 1 <= n; l++) {
      int r = l + i - 1;
      for (int mid = l; mid <= r; mid++) {
        f[l][r] = min(f[l][r], f[l][mid] + f[mid + 1][r]);
        if (f[l][mid] == f[mid + 1][r] && f[l][mid] == 1 &&
            w[l][mid] == w[mid + 1][r]) {
          f[l][r] = 1;
          w[l][r] = w[l][mid] + 1;
        }
      }
    }
  }
  printf("%d", f[1][n]);
  return 0;
}
