#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, f, g, n, m, k, t, x, h, w, q;
long long mod = 1e9 + 7;
map<long long, long long> mp;
void solve() {
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int L = 0, R = n - 1;
  int answer = 0;
  while (arr[L] == arr[R]) {
    L++;
  }
  answer = R - L;
  L = 0;
  R = n - 1;
  while (arr[L] == arr[R]) {
    R--;
  }
  answer = max(answer, R - L);
  cout << answer << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int cases = 1;
  while (cases--) {
    solve();
  }
  return 0;
}
