#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
int n;
vector<int> c;
vector<vector<int>> dp;
vector<vector<char>> pol;
const int INF = 2 * 1e9;
int go(int l, int r) {
  if (l > r) return 0;
  if (l == r) return 1;
  if (dp[l][r]) return dp[l][r];
  int res;
  res = 1 + go(l + 1, r);
  for (int i = l + 2; i <= r; ++i)
    if (c[l] == c[i]) res = min(res, go(l + 1, i - 1) + go(i + 1, r));
  if (c[l] == c[l + 1]) res = min(res, 1 + go(l + 2, r));
  return dp[l][r] = res;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  c.resize(n);
  dp.assign(n, vector<int>(n, 0));
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    --c[i];
  }
  cout << go(0, n - 1);
  return 0;
}
