#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  int c1, c2 = -1, c1i, c2i;
  c1 = c[0];
  c1i = 0;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (c2 == -1) {
      if (c[i] == c1) {
        continue;
      } else {
        c2 = c[i];
        c2i = i;
      }
    }
    if (c[i] != c1) {
      ans = max(ans, i - c1i);
    } else {
      ans = max(ans, i - c2i);
    }
  }
  cout << ans;
  return 0;
}
