#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int INF = 1e9;
long long n, a[N], dp[N][N], val[N][N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i][i] = 1;
    val[i][i] = a[i];
  }
  for (int len = 2; len <= n; len++) {
    for (int l = 1; l + len - 1 <= n; l++) {
      int r = l + len - 1;
      dp[l][r] = 1e9;
      for (int i = l; i < r; i++) {
        dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r]);
        if (dp[l][i] == 1 && dp[i + 1][r] == 1 && val[l][i] == val[i + 1][r]) {
          dp[l][r] = 1;
          val[l][r] = val[l][i] + 1;
        }
      }
    }
  }
  cout << dp[1][n];
}
