#include <bits/stdc++.h>
using namespace std;
int a[300000];
int main() {
  int n, m1 = 0, m2 = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  if (a[0] != a[n - 1]) {
    cout << n - 1;
    return 0;
  }
  while (a[m1] == a[0]) m1++;
  while (a[n - 1 - m2] == a[0]) m2++;
  cout << n - 1 - min(m1, m2);
  return 0;
}
