#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  set<pair<int, int> > s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int op = -1, j = -1;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] != a[0]) {
      op = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != a[n - 1]) {
      j = i;
      break;
    }
  }
  cout << max(abs(op), abs(n - 1 - j)) << "\n";
}
