#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; ++i) scanf("%d", &a[i]);
  int dp[n][n];
  int len, begin, end;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      dp[i][j] = 0;
    }
  }
  for (len = 1; len <= n; ++len) {
    for (begin = 0; begin + len - 1 < n; ++begin) {
      int end = begin + len - 1;
      if (len == 1)
        dp[begin][end] = 1;
      else {
        dp[begin][end] = 1 + dp[begin + 1][end];
        if (a[begin] == a[begin + 1]) {
          if (begin + 2 <= end)
            dp[begin][end] = min(dp[begin][end], 1 + dp[begin + 2][end]);
          else
            dp[begin][end] = min(dp[begin][end], 1);
        }
        for (j = begin + 2; j <= end; ++j) {
          if (a[begin] == a[j]) {
            if (j + 1 <= end)
              dp[begin][end] =
                  min(dp[begin][end], dp[begin + 1][j - 1] + dp[j + 1][end]);
            else
              dp[begin][end] = min(dp[begin][end], dp[begin + 1][j - 1]);
          }
        }
      }
    }
  }
  printf("%d", dp[0][n - 1]);
}
