#include <bits/stdc++.h>
using namespace std;
long long maximum = numeric_limits<int>::max();
long long minimum = numeric_limits<int>::min();
string gg = "abcdefghijklmnopqrstuvwxyz";
int max3(int a, int b, int c) { return max(a, max(b, c)); }
int mint(int x, int y, int z) {
  if (x < y)
    return (x < z) ? x : z;
  else
    return (y < z) ? y : z;
}
vector<pair<long long int, long long int>> v;
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  if (a.second == b.second) {
    return (a.first > b.first);
  }
  return a.second > b.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> v(n + 1);
  vector<long long int> stackk(n + 1);
  vector<long long int> dp(n + 1);
  for (long long int i = 1; i < n + 1; i++) {
    cin >> v[i];
    dp[i] = i;
  }
  for (long long int i = 1; i < n + 1; i++) {
    int counter = 0;
    for (long long int j = i; j < n + 1; j++) {
      stackk[++counter] = v[j];
      while (counter > 0) {
        if (stackk[counter] == stackk[counter - 1]) {
          counter--;
          stackk[counter]++;
        } else {
          break;
        }
      }
      dp[j] = min(dp[j], dp[i - 1] + counter);
    }
  }
  cout << dp[n];
  return 0;
}
