#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ara[300010];
  for (int i = 0; i < n; i++) {
    cin >> ara[i];
  }
  int calc1 = 0, calc2 = 0;
  for (int i = 0; i < n; i++) {
    if (ara[i] != ara[n - 1]) {
      calc1 = n - 1 - i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (ara[0] != ara[i]) {
      calc2 = i;
      break;
    }
  }
  cout << max(calc1, calc2);
}
