#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int inf = 0x3c3c3c3c;
const long long infl = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 5e5 + 9;
int a[MAX_N];
int minElements[MAX_N];
int cntElements[MAX_N];
int partialSum[MAX_N];
int main() {
  cin.tie(NULL);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    partialSum[i] = partialSum[i - 1] + (a[i] == c);
  }
  for (int i = 1; i < MAX_N; i++) {
    minElements[i] = inf;
  }
  int ans = partialSum[n];
  for (int i = 1; i <= n; i++) {
    int v = a[i];
    if (a[i] == c) {
      continue;
    }
    cntElements[v]++;
    if (minElements[v] == inf) {
      ans = max(ans, partialSum[n] + 1);
    } else {
      ans = max(ans, cntElements[v] - minElements[v] + 1 + partialSum[n] -
                         partialSum[i]);
    }
    minElements[v] = min(minElements[v], cntElements[v] - partialSum[i]);
  }
  printf("%d", ans);
}
