#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, a[maxn];
int ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = n; i >= 1; i--)
    if (a[1] != a[i]) {
      ans = max(ans, i - 1);
      break;
    }
  for (int i = 1; i <= n; i++)
    if (a[n] != a[i]) {
      ans = max(ans, n - i);
      break;
    }
  cout << ans;
  return 0;
}
