#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long i, n, x, ans1, ans2;
  vector<long long> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  for (i = 0; i < n; i++) {
    if (v[i] != v[0]) {
      ans1 = i;
    }
  }
  for (i = n - 1; i >= 0; i--) {
    if (v[i] != v[n - 1]) {
      ans2 = n - 1 - i;
    }
  }
  cout << max(ans1, ans2) << endl;
}
