#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int c[n];
  for (int i = 0; i < n; i++) cin >> c[i];
  int endi = n - 1, str = 0, inds, inde;
  if (c[0] != c[n - 1])
    return cout << n - 1 << '\n', 0;
  else {
    for (int i = 1; i < n - 1; i++)
      if (c[i] != c[0]) {
        inds = i;
        break;
      }
    for (int i = n - 2; i > -1; i--)
      if (c[i] != c[0]) {
        inde = i;
        break;
      }
  }
  cout << max(endi - inds, max(inds - str, max(endi - inde, inde - str)))
       << '\n';
  return 0;
}
