#include <bits/stdc++.h>
using namespace std;
long long int myXOR(unsigned long long int x, unsigned long long int y) {
  return (x | y) & (~x | ~y);
}
long long int powerLL(long long int x, long long int n) {
  long long int result = 1;
  while (n) {
    if (n & 1) result = result * x % 1000000007;
    n = n / 2;
    x = x * x % 1000000007;
  }
  return result;
}
int main() {
  long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, t, u, w,
      x, y, z;
  cin >> n;
  long long int arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int maxlen = LLONG_MIN;
  for (i = n - 1; i > 0; i--) {
    if (arr[i] != arr[0]) {
      maxlen = max(maxlen, i);
      break;
    }
  }
  for (i = 0; i < n - 1; i++) {
    if (arr[i] != arr[n - 1]) {
      maxlen = max(maxlen, n - i - 1);
      break;
    }
  }
  cout << maxlen;
}
