#include <bits/stdc++.h>
using namespace std;
int c[300005];
int vis[300005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
  }
  int co = 0;
  int l = 1, r = n, maxn = 0;
  while (true) {
    if (vis[c[l]]) {
    } else {
      vis[c[l]] = 1;
      co++;
      if (co > 1) {
        maxn = n - l;
        break;
      }
    }
    if (vis[c[r]]) {
    } else {
      vis[c[r]] = 1;
      co++;
      if (co > 1) {
        maxn = r - 1;
        break;
      }
    }
    l++;
    r--;
  }
  printf("%d", maxn);
}
