#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  int ans = -1;
  for (int i = 0; i < n; ++i) {
    if (c[i] != c[0]) {
      ans = max(ans, i);
    }
    if (c[i] != c[n - 1]) {
      ans = max(ans, n - i - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
