#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[505];
  int dp[505];
  for (int i = 1; i <= n; i++) cin >> a[i];
  dp[n + 1] = 0;
  for (int i = n; i > 0; i--) {
    stack<int> s;
    s.push(99999);
    dp[i] = 99999;
    for (int j = i; j <= n; j++) {
      int x = a[j];
      if (!s.empty())
        while (s.top() == x) {
          s.pop();
          x++;
        }
      s.push(x);
      x = s.size() - 1;
      dp[i] = min(dp[i], x + dp[j + 1]);
    }
  }
  cout << dp[1] << endl;
  return 0;
}
