#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, s = 0, a = 0;
  cin >> n;
  long int c[n];
  for (long int i = 0; i < n; i++) cin >> c[i];
  a = n - 1;
  while (c[0] == c[a] && c[0] == c[n - a - 1]) {
    a--;
  }
  cout << a;
  return 0;
}
