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