#include <bits/stdc++.h>
using namespace std;
int n;
int v[300010];
pair<int, int> p[300010];
int main() {
  cin >> n;
  int in = 0;
  for (int i = 1; i <= n; i++) {
    cin >> v[i], p[v[i]].second = i;
    if (p[v[i]].first == 0) p[v[i]].first = i;
    if (i != 1 && in == 0 && v[i] != v[i - 1]) in = i;
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    int l = 1;
    if (p[i].first == 1) l = in;
    mx = max(abs(p[i].second - l), mx);
  }
  cout << mx;
}
