#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int N = (int)1e3 + 10;
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
int dp[N][N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i][i] = a[i];
  }
  for (int len = 2; len <= n; len++) {
    for (int i = 1; i <= n; i++) {
      if (i + len - 1 > n) break;
      for (int j = i; j <= i + len - 1; j++) {
        if (dp[i][j] && dp[i][j] == dp[j + 1][i + len - 1]) {
          dp[i][i + len - 1] = dp[i][j] + 1;
        }
      }
    }
  }
  vector<int> dp2(n + 1);
  dp2[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp2[i] = dp2[i - 1] + 1;
    for (int j = 1; j < n; j++) {
      if (dp[j + 1][i]) {
        dp2[i] = min(dp2[i], dp2[j] + (dp[1][j] != dp[j + 1][i]));
      }
    }
  }
  cout << dp2[n] << endl;
  return 0;
}
