#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
static constexpr int INF = (int)1e9 + 5;
static constexpr ll INFL = (ll)1e18 + 5;
static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(
                       chrono::high_resolution_clock::now().time_since_epoch())
                       .count());
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vi a(n);
  for (auto& ai : a) cin >> ai;
  vi dp(n + 1);
  for (int i = n - 1; i >= 0; --i) {
    vi st;
    dp[i] = INF;
    for (int j = (i); j < (n); ++j) {
      st.push_back(a[j]);
      while (((int)(st).size()) >= 2 && st.back() == st[((int)(st).size()) - 2])
        st.pop_back(), st.back()++;
      if (((int)(st).size()) == 1) dp[i] = min(dp[i], 1 + dp[j + 1]);
    }
  }
  cout << dp[0] << '\n';
  return 0;
}
