#include <bits/stdc++.h>
using namespace std;
long long c[570000];
int main() {
  int n, Max = 0, i;
  cin >> n;
  int l, r;
  for (i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (i = 1; i < n; i++) {
    if (c[n] != c[i]) {
      l = n - i;
      break;
    }
  }
  for (i = n; i >= 2; i--) {
    if (c[1] != c[i]) {
      r = i - 1;
      break;
    }
  }
  cout << max(l, r);
  return 0;
}
