#include <bits/stdc++.h>
using namespace std;
const int N = 500, A = 1008;
int aa[N], ii[N][A + 1], dp[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> aa[i];
  for (int j = 0; j < n; j++) {
    fill_n(ii[j], A + 1, -2);
    int a = aa[j];
    ii[j][a] = j - 1;
    while (++a <= A &&
           (ii[j][a] = ii[j][a - 1] >= 0 ? ii[ii[j][a - 1]][a - 1] : -2) != -2)
      ;
    int x = n + 1;
    for (int a = 1; a <= A; a++) {
      int i = ii[j][a];
      if (i != -2) x = min(x, (i != -1 ? dp[i] : 0) + 1);
    }
    dp[j] = x;
  }
  cout << dp[n - 1] << '\n';
  return 0;
}
