#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int INF = 1e10;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (auto &x : a) cin >> x;
  long long int dp[n + 1][n + 1];
  long long int dp2[n];
  memset(dp, -1, sizeof(dp));
  for (long long int len = 1; len <= n; len++) {
    for (long long int i = 0; i < n - len + 1; i++) {
      long long int j = i + len - 1;
      if (i == j)
        dp[i][j] = a[i];
      else {
        for (long long int k = i; k < j; k++) {
          if (dp[i][k] != -1 && dp[i][k] == dp[k + 1][j])
            dp[i][j] = dp[i][k] + 1;
        }
      }
    }
  }
  for (long long int i = 0; i < n; i++) dp2[i] = i + 1;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j <= i; j++) {
      if (dp[j][i] != -1) {
        if (j == 0) dp2[i] = 1;
        dp2[i] = min(dp2[i], dp2[j - 1] + 1);
      }
    }
  }
  cout << dp2[n - 1];
  return 0;
}
