#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> data(n + 1);
  for (int i = 1; i <= n; i++) cin >> data[i];
  int i = 1, j = n;
  while (j > i && data[j] == data[1]) j--;
  while (i < j && data[i + 1] == data[1]) i++;
  cout << max(j - 1, max(j - i, n - i - 1)) << endl;
}
