#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long> v;
  long n, i, j, k;
  cin >> n;
  for (i = 0; i < n; i++) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  if (v[0] != v[n - 1]) {
    cout << n - 1;
  } else {
    i = n - 1;
    while (v[i] == v[0]) {
      i--;
    }
    j = 1;
    while (v[j] == v[0]) {
      j++;
    }
    long t = max(i, n - 1 - i);
    long p = max(j, n - 1 - j);
    cout << max(t, p);
  }
}
