#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int val = arr[0];
  int mx = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] != val) {
      mx = max(mx, i);
      break;
    }
  }
  val = arr[n - 1];
  for (int i = 0; i < n; i++) {
    if (arr[i] != val) {
      mx = max(mx, n - i - 1);
      break;
    }
  }
  cout << mx << endl;
  return 0;
}
