#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 505;
int a[maxn], dp[maxn][maxn];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      dp[i][j] = 999;
    }
  }
  for (int i = 0; i < n; ++i) {
    dp[i][i] = 1;
  }
  for (int len = 2; len <= n; ++len) {
    for (int i = 0; i + len - 1 < n; ++i) {
      int j = i + len - 1;
      if (a[i] == a[j]) {
        if (len == 2) {
          dp[i][j] = 1;
        } else {
          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\n", dp[0][n - 1]);
  return 0;
}
