#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 10;
int color[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) {
    cin >> color[i];
  }
  int c = color[n - 1];
  int cnt1 = 0;
  for (int i = 0; i <= n - 1; i++) {
    if (color[i] != c) {
      cnt1 = n - 1 - i;
      break;
    }
  }
  int cnt2 = 0;
  c = color[0];
  for (int i = n - 1; i >= 0; i--) {
    if (color[i] != c) {
      cnt2 = i;
      break;
    }
  }
  cout << max(cnt1, cnt2) << endl;
  return 0;
}
