#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k;
  long long n, c;
  cin >> n >> c;
  vector<long long> v(n);
  for (i = (0); i < (n); i++) cin >> v[i];
  vector<long long> temp(n), z1(n, 0), z2(n, 0);
  for (i = (0); i < (n); i++) temp[i] = (v[i] - c);
  long long zc = 0;
  for (i = (0); i < (n); i++) {
    if (temp[i] == 0) {
      z1[i] = (((i > 0) ? z1[i - 1] : 0) + 1);
      zc++;
    } else
      z1[i] = ((i > 0) ? z1[i - 1] : 0);
  }
  for (i = n - 1; i >= 0; i--) {
    if (temp[i] == 0)
      z2[i] = (((i < (n - 1)) ? z2[i + 1] : 0) + 1);
    else
      z2[i] = ((i < (n - 1)) ? z2[i + 1] : 0);
  }
  map<long long, pair<long long, long long> > mvp;
  long long ans = max(zc, 1ll);
  for (i = (0); i < (n); i++) {
    if (temp[i] == 0) continue;
    long long curr =
        1 + (((i > 0) ? z1[i - 1] : 0)) + (((i < (n - 1)) ? z2[i + 1] : 0));
    if (mvp.find(temp[i]) != mvp.end()) {
      if ((z1[i] - ((mvp[temp[i]].first > 0) ? z1[mvp[temp[i]].first - 1]
                                             : 0)) >= mvp[temp[i]].second) {
        mvp[temp[i]].first = -1;
        mvp[temp[i]].second = 0;
      } else
        curr = max(
            curr, ((i < (n - 1)) ? z2[i + 1] : 0) +
                      (((mvp[temp[i]].first) > 0) ? z1[(mvp[temp[i]].first) - 1]
                                                  : 0) +
                      (mvp[temp[i]].second) + 1);
    } else
      mvp.insert(make_pair(temp[i], make_pair(-1, 0)));
    if (mvp[temp[i]].first == -1) mvp[temp[i]].first = i;
    mvp[temp[i]].second++;
    ans = max(ans, curr);
  }
  cout << ans << '\n';
  return 0;
}
