#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
long long fr[1000000];
vector<pair<long long, long long>> vc, mc;
int32_t main() {
  fastio();
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  vc.push_back(make_pair(a[n - 1], n));
  for (long long i = n - 2; i >= 0; i--) {
    if (a[i] != a[i + 1]) vc.push_back(make_pair(a[i], i + 1));
  }
  long long j = 0;
  long long mx = 0;
  if (a[0] != vc[0].first) {
    mx = vc[0].second - 1;
  }
  if (a[0] != vc[1].first) {
    long long tt = vc[1].second - (1);
    if (tt > mx) mx = tt;
  }
  for (long long i = 1; i < n; i++) {
    if (a[i] != a[0]) {
      if (a[i] != vc[0].first) {
        long long tt = vc[0].second - (i + 1);
        if (tt > mx) mx = tt;
      }
      if (a[i] != vc[1].first) {
        long long tt = vc[1].second - (i + 1);
        if (tt > mx) mx = tt;
      }
      break;
    }
  }
  cout << mx;
}
