#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << "\n";
  err(++it, args...);
}
const int MOD = 1e9 + 7, N = 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    ;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != a[0]) ans = max(ans, i);
      if (a[i] != a[n - 1]) ans = max(ans, n - 1 - i);
    }
    cout << ans;
  }
}
