#include <bits/stdc++.h>
#pragma target("avx")
using namespace std;
constexpr long long INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr long long LINF = 1e18;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
long long n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
long long dp[600][600], val[600][600];
int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (long long(i) = 0; (i) < (int)(n); (i)++) cin >> a[i];
  for (long long(i) = 0; (i) < (int)(n + 1); (i)++)
    for (long long(j) = 0; (j) < (int)(n + 1); (j)++) dp[i][j] = LINF;
  for (long long(i) = 0; (i) < (int)(n); (i)++) {
    dp[i][i] = 1;
    val[i][i] = a[i];
  }
  for (long long diff = (1); diff < (n); diff++) {
    for (long long(i) = 0; (i) < (int)(n); (i)++) {
      long long j = i + diff;
      if (j >= n) continue;
      for (long long k = (i); k < (j); k++) {
        if (dp[i][k] == 1 && dp[k + 1][j] == 1 && val[i][k] == val[k + 1][j]) {
          dp[i][j] = 1;
          val[i][j] = val[i][k] + 1;
        } else {
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
        }
      }
    }
  }
  cout << (dp[0][n - 1]) << endl;
  return 0;
}
