#include <bits/stdc++.h>
using namespace std;
int n, c[300005], p1, p2, dif1, dif2;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  if (c[1] != c[n])
    cout << n - 1;
  else {
    for (int i = n - 1; i >= 1; i--) {
      if (c[i] != c[1]) {
        p1 = i;
        break;
      }
    }
    for (int i = 2; i <= n - 1; i++) {
      if (c[i] != c[1]) {
        p2 = i;
        break;
      }
    }
    dif1 = p1 - 1;
    dif2 = n - p2;
    cout << max(dif1, dif2);
  }
  return 0;
}
