#include <bits/stdc++.h>
using namespace std;
int c[300005];
int a[300005];
void find() {
  int n;
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) cin >> a[i], c[i] = -1;
  set<int> s;
  s.clear();
  int ans = INT_MIN;
  for (i = 1; i <= n; i++) {
    int x = a[i];
    if (c[x] == -1) {
      if (s.size())
        ans = max(ans, abs(max(i - *s.begin(), abs(*s.rbegin() - i))));
      s.insert(i);
      c[x] = i;
    } else {
      int y = c[x];
      s.erase(y);
      if (s.size())
        ans = max(ans, abs(max(i - *s.begin(), abs(*s.rbegin() - i))));
      s.insert(y);
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  t = 1;
  while (t--) {
    find();
  }
  return 0;
}
