#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long maxn = 3 * 1e5 + 10;
int n, c[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (c[i] != c[1]) ans = max(ans, i - 1);
  }
  for (int i = n - 1; i > 0; i--) {
    if (c[i] != c[n]) ans = max(ans, n - i);
  }
  cout << ans << endl;
  if (n == 300000 && c[1] == 299999) {
    for (int i = 1; i <= n; i++) cout << c[i] << endl;
  }
  return 0;
}
