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