#include <bits/stdc++.h>
using namespace std;
int n;
int A[300008];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];
  ;
  if (A[0] != A[n - 1]) return cout << n - 1, 0;
  int mx = 0;
  for (int i = 1; i < n; i++) {
    if (A[i] != A[0]) {
      mx = i;
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    if (A[i] != A[n - 1]) {
      mx = max(mx, (n - 1) - i);
    }
  }
  cout << mx;
  cout << endl;
}
