#include <bits/stdc++.h>
using namespace std;
int n;
int a[5010];
int dp[5010][5010][2];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    dp[i][i][0] = dp[i][i][1] = 0;
  }
  for (int j = 1; j < n; j++) {
    for (int i = 1; i + j <= n; i++) {
      dp[i][i + j][0] = dp[i][i + j][1] = 9999;
      if (a[i + 1] == a[i]) {
        dp[i][i + j][0] = min(dp[i][i + j][0], dp[i + 1][i + j][0]);
      }
      if (a[j + i] == a[i]) {
        dp[i][i + j][0] = min(dp[i][i + j][0], dp[i + 1][i + j][1]);
      }
      dp[i][i + j][0] = min(dp[i][i + j][0], min(dp[i + 1][i + j][0] + 1,
                                                 dp[i + 1][i + j][1] + 1));
      if (a[i + j] == a[i]) {
        dp[i][i + j][1] = min(dp[i][i + j][1], dp[i][i + j - 1][0]);
      }
      if (a[i + j] == a[i + j - 1]) {
        dp[i][i + j][1] = min(dp[i][i + j][1], dp[i][i + j - 1][1]);
      }
      dp[i][i + j][1] = min(dp[i][i + j][1], min(dp[i][i + j - 1][0] + 1,
                                                 dp[i][i + j - 1][1] + 1));
    }
  }
  cout << min(dp[1][n][0], dp[1][n][1]) << endl;
  return 0;
}
