#include <bits/stdc++.h>
using namespace std;
long long powmod(long long base, long long exponent, long long mod) {
  long long ans = 1;
  while (exponent) {
    if (exponent & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    exponent /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
const int upperlimit = 1e6 + 100;
const int mod = 1e9 + 7;
int arr[upperlimit];
int main() {
  int k1, k2;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  for (int i = 2; i <= n; i++) {
    if (arr[i] != arr[i - 1]) {
      k1 = i;
      break;
    }
  }
  for (int i = n; i > 1; i--) {
    if (arr[i] != arr[i - 1]) {
      k2 = i - 1;
      break;
    }
  }
  if (arr[1] != arr[n])
    printf("%d", n - 1);
  else
    printf("%d", max(n - k1, k2 - 1));
  return 0;
}
