#include <bits/stdc++.h>
using namespace std;
int A[500007];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }
  int x, y;
  x = 1;
  y = n;
  while (A[x] == A[y]) {
    y--;
  }
  int ansy = y - x;
  x = 1;
  y = n;
  while (A[x] == A[y]) {
    x++;
  }
  int ansx = y - x;
  printf("%d\n", max(ansx, ansy));
  return 0;
}
