#include <bits/stdc++.h>
using namespace std;
int n, nums[300300];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &nums[i]);
  }
  int ans = 0;
  for (int j = n - 1; j >= 0; j--)
    if (nums[j] != nums[0]) {
      ans = j;
      break;
    }
  for (int i = 0; i < n; i++)
    if (nums[i] != nums[n - 1]) {
      ans = max(ans, n - 1 - i);
      break;
    }
  printf("%d\n", ans);
  return 0;
}
