#include <bits/stdc++.h>
const int MAX_N = 5e2 + 5;
int n, f[MAX_N][MAX_N], g[MAX_N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &f[i][i]);
  for (int l = 1; l < n; ++l)
    for (int i = 1; i + l <= n; ++i)
      for (int j = i; j < i + l; ++j)
        if (f[i][j] && f[i][j] == f[j + 1][i + l]) f[i][i + l] = f[i][j] + 1;
  for (int i = 1; i <= n; ++i) {
    g[i] = i;
    for (int j = 1; j <= i; ++j)
      if (f[j][i]) g[i] = std::min(g[i], g[j - 1] + 1);
  }
  printf("%d\n", g[n]);
  return 0;
}
