#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<vector<int>> d(n, vector<int>(n, -1));
  for (int i = 0; i < n; ++i) {
    d[i][i] = a[i];
  }
  for (int len = 2; len <= n; ++len) {
    for (int L = 0; L + len - 1 < n; ++L) {
      int R = L + len - 1;
      for (int i = L; i < R; ++i) {
        if (d[L][i] != -1 && d[L][i] == d[i + 1][R]) d[L][R] = d[L][i] + 1;
      }
    }
  }
  vector<int> ans(n + 1, 1e9);
  ans[0] = 0;
  for (int R = 1; R <= n; ++R) {
    for (int L = 1; L <= R; ++L) {
      if (d[L - 1][R - 1] != -1) ans[R] = min(ans[R], ans[L - 1] + 1);
    }
  }
  cout << ans[n];
  return 0;
}
