#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int col[n];
  for (int i = 0; i < n; i++) cin >> col[i];
  int a = col[0], b;
  int j = 0;
  for (int i = 0; i < n; i++)
    if (a != col[i]) {
      b = col[i];
      j = i;
      break;
    }
  int maxi = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (col[i] != a) {
      maxi = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (col[i] != b) {
      maxi = max(i - j, maxi);
      break;
    }
  }
  cout << maxi;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
