#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  int i = 1;
  while (i <= n && arr[i] == arr[n]) {
    i++;
  }
  int j = n;
  while (j >= 0 && arr[j] == arr[1]) {
    j--;
  }
  cout << max(n - i, j - 1) << endl;
}
