#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 5e5 + 10;
int a[maxn];
map<int, int> flag;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (flag[a[i]] == 1) continue;
    flag[a[i]] = 1;
    for (int j = n - 1; j > i; j--) {
      if (a[j] != a[i]) {
        if (j - i > res) {
          res = j - i;
        }
        break;
      }
      if (j - i < res) break;
    }
  }
  printf("%d", res);
}
