#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> v;
int main() {
  scanf("%d", &N);
  v.resize(N);
  for (int i = 0; i < N; i++) scanf("%d", &v[i]);
  int a = v[0];
  if (a != v[N - 1]) return !printf("%d", N - 1);
  int lo = 1, hi = N - 2, res = N - 2;
  while (lo <= hi) {
    if (a != v[hi] || a != v[lo]) return !printf("%d", res);
    lo++;
    hi--;
    res--;
  }
  return 0;
}
