#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
map<long long, long long> ind;
long long n, c, arr[N], pref[N];
vector<long long> vals[N];
long long prevind[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> c;
  pref[0] = 0;
  for (long long i = 0; i < N; i++) prevind[i] = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
    pref[i] = pref[i - 1];
    ind[c - arr[i]] = 0;
    if (arr[i] == c) pref[i]++;
  }
  long long ct = 0;
  map<long long, long long>::iterator it;
  long long ans = pref[n];
  for (it = ind.begin(); it != ind.end(); it++) {
    it->second = ct++;
  }
  for (long long i = 1; i <= n; i++) {
    long long uind = ind[c - arr[i]];
    if (!vals[uind].empty()) {
      long long tval = prevind[uind];
      vals[uind].push_back(-pref[i] + pref[tval]);
    }
    vals[uind].push_back(1);
    prevind[uind] = i;
  }
  long long cval = -1;
  if (ind.find(0) != ind.end()) {
    cval = ind[0];
  }
  for (long long i = 0; i < ct; i++) {
    if (i == cval) continue;
    long long mx = 0;
    for (auto j : vals[i]) {
      mx = max(j, mx + j);
      ans = max(ans, mx + pref[n]);
    }
  }
  cout << ans;
}
