#include <bits/stdc++.h>
using namespace std;
int c[300010], vis1[300010], vis2[300010], vis[300010];
int cnt;
int main() {
  int n = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    if (vis1[c[i]])
      vis2[c[i]] = i;
    else {
      vis1[c[i]] = i;
      vis[cnt++] = c[i];
    }
  }
  int ans = 0;
  for (int k = 0; k < cnt; k++) {
    int i = vis[k];
    int x = vis1[i];
    int y = vis2[i];
    int temp = 0;
    if (x && y) {
      if (x != 1 && y != n)
        temp = max(n - x, y - 1);
      else if (x != 1)
        temp = y - 1;
      else if (y != n)
        temp = n - x;
    } else if (x) {
      temp = max(n - x, x - 1);
    }
    ans = max(ans, temp);
  }
  cout << ans;
  getchar();
  getchar();
  return 0;
}
