#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
template <typename T>
void chmin(T &a, const T &b) {
  a = min(a, b);
}
template <typename T>
void chmax(T &a, const T &b) {
  a = max(a, b);
}
struct FastIO {
  FastIO() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} fastiofastio;
const ll INF = 1LL << 60;
int main(void) {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = (ll)0; i < (ll)n; ++i) cin >> a[i];
  vector<vector<ll>> dp(n, vector<ll>(n, INF));
  vector<vector<ll>> val(n, vector<ll>(n, -1));
  for (ll i = (ll)0; i < (ll)n; ++i) dp[i][i] = 1, val[i][i] = a[i];
  for (ll w = (ll)2; w < (ll)n + 1; ++w)
    for (ll l = (ll)0; l < (ll)n - w + 1; ++l) {
      ll r = l + w - 1;
      for (ll i = (ll)l; i < (ll)r; ++i) {
        if (dp[l][i] == 1 && dp[i + 1][r] == 1 && val[l][i] == val[i + 1][r]) {
          chmin(dp[l][r], 1LL);
          val[l][r] = val[l][i] + 1;
        } else {
          chmin(dp[l][r], dp[l][i] + dp[i + 1][r]);
        }
      }
    }
  cout << dp[0][n - 1] << endl;
  return 0;
}
