#include <bits/stdc++.h>
using namespace std;
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long n;
  cin >> n;
  ;
  vector<long long> data(n);
  for (long long i = 0; i < n; i++) {
    cin >> data[i];
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (data.back() != data[i]) {
      ans = n - i - 1;
      break;
    }
  }
  for (long long i = n - 1; i > 0; i--) {
    if (data[0] != data[i]) {
      ans = max(ans, i);
      break;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
