#include <bits/stdc++.h>
using namespace std;
const int nmax = 5 * 100 * 1000 + 5;
vector<int> v[nmax];
int pref[nmax], suf[nmax], a[nmax];
int n, k, prf, x, i, mx, j;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> x;
    a[i] = x;
    v[x].push_back(i);
    pref[i] = pref[i - 1] + (x == k);
  }
  for (i = n; i >= 1; i--) suf[i] = suf[i + 1] + (a[i] == k);
  mx = pref[n];
  for (i = 1; i <= 5 * 100 * 1000; i++) {
    prf = 0;
    for (j = 0; j < v[i].size(); j++) {
      prf = max(prf, pref[v[i][j] - 1] - j);
      mx = max(mx, prf + suf[v[i][j] + 1] + j + 1);
    }
  }
  cout << mx;
  return 0;
}
