#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  int n, a[300000] = {}, b, c, x, y;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  b = a[0], c = a[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] != b) {
      x = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != c) {
      y = n - 1 - i;
      break;
    }
  }
  cout << max(x, y) << endl;
}
