#include <bits/stdc++.h>
using namespace std;
int n;
int c[300005];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> c[i];
  if (c[0] != c[n - 1])
    printf("%d\n", n - 1);
  else {
    int p = 1, q = n - 2;
    while (c[p] == c[0] && c[q] == c[0]) {
      p++;
      q--;
    }
    int x = 300005 + 5;
    if (p != c[0])
      x = max(p - 0, n - 1 - p);
    else
      x = max(q - 0, n - 1 - q);
    cout << x << '\n';
  }
}
