#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, a[N], ans;
struct node {
  int col, id;
};
void solved() {
  node max1, max2;
  max1.id = -1, max2.id = -1;
  for (int i = 1; i <= n; i++) {
    if (max1.id != -1 && max1.col != a[i]) ans = max(ans, i - max1.id);
    if (max2.id != -1 && max2.col != a[i]) ans = max(ans, i - max2.id);
    if (max1.id == -1)
      max1 = (node){a[i], i};
    else if (max2.id == -1 && a[i] != max1.col)
      max2 = (node){a[i], i};
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  solved();
  for (int i = 1; i <= n / 2; i++) swap(a[i], a[n - i + 1]);
  solved();
  printf("%d\n", ans);
  return 0;
}
