#include <bits/stdc++.h>
using namespace std;
const int maxn = 501;
int dp[maxn][maxn];
int n;
int a[maxn];
int dp2[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], dp[i][i] = a[i];
  for (int len = 1; len <= n; len++) {
    for (int i = 1; i <= n - len + 1; i++) {
      for (int k = i; k < i + len - 1; k++) {
        if (dp[i][k] != 0 && dp[i][k] == dp[k + 1][i + len - 1]) {
          dp[i][i + len - 1] = dp[i][k] + 1;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    dp2[i] = dp2[i - 1] + 1;
    for (int j = 1; j < i; j++) {
      if (dp[j][i] > 0) {
        dp2[i] = min(dp2[i], dp2[j - 1] + 1);
      }
    }
  }
  printf("%d\n", dp2[n]);
  return 0;
}
