#include <bits/stdc++.h>
using namespace std;
int solve(vector<vector<int> > &ans, const vector<int> &x, int a, int b) {
  if (ans[a][b] != -1) {
    return ans[a][b];
  }
  if (a + 1 == b) {
    ans[a][b] = 1;
    return ans[a][b];
  }
  if (a == b) {
    return 1;
  }
  int res = x.size();
  res = min(res, solve(ans, x, a + 1, b) + 1);
  for (int i = a + 1; i < b; ++i) {
    if (x[i] == x[a]) {
      int temp = solve(ans, x, a + 1, i);
      if (i + 1 != b) {
        temp += solve(ans, x, i + 1, b);
      }
      res = min(res, temp);
    }
  }
  ans[a][b] = res;
  return res;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout.setf(ios_base::fixed);
  cout.precision(3);
  int n, m;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  n++;
  vector<vector<int> > ans(n, vector<int>(n, -1));
  cout << solve(ans, x, 0, n - 1);
  return 0;
}
