#include <bits/stdc++.h>
using namespace std;
int v[312345];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int m1 = 0, m2 = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] != v[0]) m1 = max(m1, abs(i - 0));
  }
  for (int i = 0; i < n; i++) {
    if (v[i] != v[n - 1]) {
      m2 = abs(i - (n - 1));
      break;
    }
  }
  cout << max(m1, m2) << endl;
  return 0;
}
