#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N);
  long long res = 0;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (long long i = 0; i < N; i++) {
    if (A[i] != A[0]) {
      res = max(res, i);
    }
  }
  for (long long i = 0; i < N; i++) {
    if (A[i] != A[N - 1]) {
      res = max(res, N - 1 - i);
    }
  }
  cout << res << endl;
}
