#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long MAXN = 1e5 + 7;
const long long MOD = 1e9 + 1;
long long a[1515151];
int main() {
  long long n;
  cin >> n;
  long long sum = 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]) sum = max(sum, i);
  }
  for (long long i = 0; i < n; i++) {
    if (a[n - 1] != a[i]) sum = max(sum, n - i - 1);
  }
  cout << sum;
}
