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