#include <bits/stdc++.h>
using namespace std;
const int max_n = 505;
int n, a[max_n];
int dp[max_n];
vector<int> stk;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) {
    dp[i] = i;
    stk.clear();
    for (int j = i; j >= 1; j--) {
      int x = a[j];
      while (!stk.empty() && stk.back() == x) x++, stk.pop_back();
      stk.push_back(x);
      if (stk.size() == 1) dp[i] = min(dp[j - 1] + 1, dp[i]);
    }
  }
  printf("%d\n", dp[n]);
  return 0;
}
