#include <bits/stdc++.h>
using namespace std;
const int MX = 300005;
int n, c[MX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> c[i];
  int res = 0, i = n - 1;
  while (c[0] == c[i]) i--;
  res = i;
  i = 0;
  while (c[i] == c[n - 1]) i++;
  res = max(res, n - i - 1);
  cout << res << '\n';
  return 0;
}
