#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int c[300005];
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  int max = 1;
  for (int i = 1; i <= n; i++) {
    if (c[i] != c[1]) {
      if ((i - 1) > max) max = i - 1;
    }
  }
  for (int i = n; i >= 1; i--) {
    if (c[i] != c[n]) {
      if ((n - i) > max) max = n - i;
    }
  }
  printf("%d", max);
}
