#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INFll = 1ll * 1000000009 * 1000000009;
const long double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  int r;
  for (ll i = n - 1; i >= 0; i--)
    if (a[0] != a[i]) {
      r = i;
      break;
    }
  for (ll i = 0; i < n; i++)
    if (a[n - 1] != a[i]) {
      r = (r > n - 1 - i) ? r : n - 1 - i;
      break;
    }
  cout << r << '\n';
}
