#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
const int MAXN = 3e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e7 + 9;
int a[MAXN];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); ++i) {
    scanf("%d", &a[i]);
  }
  int ans1 = 0;
  int t1 = 1;
  for (int i = (n); i > (0); --i) {
    if (a[t1] != a[i]) {
      ans1 = i - t1;
      break;
    } else {
      t1++;
      i++;
    }
  }
  int ans2 = 0;
  int t2 = n;
  for (int i = (1); i < (n + 1); ++i) {
    if (a[t2] != a[i]) {
      ans2 = t2 - i;
      break;
    } else {
      t2--;
      i--;
    }
  }
  printf("%d\n", max(ans1, ans2));
  return 0;
}
