#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> c(n);
  int a = 0, b = 0;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  for (int i = n - 1; i > 0; --i) {
    if (c[i] != c[0]) {
      b = i;
      break;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (c[i] != c[n - 1]) {
      a = n - i - 1;
      break;
    }
  }
  cout << max(a, b);
  return 0;
}
