#include <bits/stdc++.h>
using namespace std;
template <class my>
my aabs(const my& a) {
  return (a > 0) ? a : -a;
}
long long int gcd(long long int a, long long int b) {
  return (b == 0) ? a : gcd(b, a % b);
}
long long int LSOne(long long int k) { return (k & (-k)); }
int visited[1002][1002] = {}, val[1002][1002], values[1000001] = {0};
int dr[] = {1, 0, -1, 0}, dc[] = {0, 1, 0, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, arr[300001];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  int j = 0, k = n - 1;
  for (;; j++)
    if (arr[j] != arr[n - 1]) break;
  j = n - 1 - j;
  for (;; k--)
    if (arr[k] != arr[0]) break;
  if (j > k) k = j;
  cout << k << endl;
}
