#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  x = 0;
  char c = getchar();
  int p = 1;
  for (; c < 48; c = getchar())
    if (c == '-') p = -1;
  for (; c > 47; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  x *= p;
}
void read(long long &x) {
  x = 0;
  char c = getchar();
  int p = 1;
  for (; c < 48; c = getchar())
    if (c == '-') p = -1;
  for (; c > 47; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  x *= p;
}
void Min(int &x, int y) {
  if (x > y) x = y;
}
void Min(long long &x, long long y) {
  if (x > y) x = y;
}
void Max(int &x, int y) {
  if (x < y) x = y;
}
void Max(long long &x, long long y) {
  if (x < y) x = y;
}
bool stttt;
int n, a[500005], l, r;
bool edddd;
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
  }
  int res = 0;
  l = 1;
  r = n;
  for (; a[l] == a[r];) {
    if (a[l + 1] != a[r] || a[l] != a[r - 1]) {
      Max(res, (r - (l + 1)));
      break;
    }
    l++;
    r--;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[n]) Max(res, n - i);
    if (a[i] != a[1]) Max(res, i - 1);
  }
  printf("%d\n", res);
  return 0;
}
