#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n;
int d[N][N], f[N], a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], d[i][i] = a[i];
  for (int len = 2; len <= n; len++) {
    for (int l = 1; l + len - 1 <= n; l++) {
      int r = l + len - 1;
      for (int k = l; k < r; k++) {
        if (d[l][k] && d[l][k] == d[k + 1][r]) d[l][r] = d[l][k] + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    f[i] = 1e9;
    for (int j = 1; j <= i; j++) {
      if (d[j][i]) f[i] = min(f[i], f[j - 1] + 1);
    }
  }
  cout << f[n] << endl;
  return 0;
}
