#include <bits/stdc++.h>
using namespace std;
pair<int, int> dir[] = {{-1, 0}, {1, 0},  {0, 1},  {0, -1},
                        {1, 1},  {1, -1}, {-1, 1}, {-1, -1}};
int N, arr[300005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  int maxV = 0;
  for (int i = 1; i <= N; i++) cin >> arr[i];
  for (int j = N; j >= 2; j--) {
    if (arr[1] != arr[j]) {
      maxV = max(maxV, j - 1);
      break;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (arr[i] != arr[N]) {
      maxV = max(maxV, N - i);
      break;
    }
  }
  cout << maxV;
}
