#include <bits/stdc++.h>
using namespace std;
int n, a[502], dp[502][502];
signed main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) dp[i][j] = 0x7ffffffa;
  for (int i = 1; i <= n; ++i) dp[i][i] = 1;
  for (int i = 1; i < n; ++i) dp[i][i + 1] = 1 + (a[i] != a[i + 1]);
  for (int h = 3; h <= n; ++h)
    for (int i = 1; i <= n + 1 - h; ++i) {
      int j = i + h - 1;
      if (a[i] == a[j]) dp[i][j] = dp[i + 1][j - 1];
      for (int k = i; k < j; ++k)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
    }
  printf("%d", dp[1][n]);
  return 0;
}
