#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int maxn = 500 + 5;
const long double eps = 1e-6;
long double PI = acos((long double)(-1));
int n;
int c[maxn];
int dp[maxn][maxn];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  for (int len = 1; len <= n; len++) {
    for (int beg = 0, end = len - 1; end < n; beg++, end++) {
      if (len == 1)
        dp[beg][end] = 1;
      else {
        dp[beg][end] = 1 + dp[beg + 1][end];
        if (c[beg] == c[beg + 1])
          dp[beg][end] = min(dp[beg][end], 1 + dp[beg + 2][end]);
        for (int k = beg + 2; k <= end; k++)
          if (c[beg] == c[k])
            dp[beg][end] =
                min(dp[beg][end], dp[beg + 1][k - 1] + dp[k + 1][end]);
      }
    }
  }
  printf("%d\n", dp[0][n - 1]);
  return 0;
}
