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