#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long LINF = 1ll << 60;
const int MOD = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 0;
  cin >> n;
  vector<int> arr(n);
  for (auto &i : arr) {
    cin >> i;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] != arr[n - 1]) {
      ans = max(ans, n - 1 - i);
      break;
    }
  }
  for (int i = n - 1; i > -1; i--) {
    if (arr[0] != arr[i]) {
      ans = max(ans, i);
      break;
    }
  }
  cout << ans;
  return 0;
}
