#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long N = 1e6 + 36;
const long long M = 5e5;
const long long INF = 2e9 + 7;
const long long MOD = 987654323;
const long long MOD1 = 1e9 + 7;
const long long MOD2 = 1e9 + 9;
const int XK[4] = {-1, 0, 1, 0};
const int YK[4] = {0, -1, 0, 1};
const int X[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int Y[8] = {2, -2, 2, -2, 1, -1, 1, -1};
vector<int> g[N];
int a[N], pref[N], suf[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, c;
  cin >> n >> c;
  for (int i(1); i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = c - x;
    g[a[i] + M].push_back(i);
  }
  for (int i(1); i <= n; ++i) {
    pref[i] = pref[i - 1];
    if (a[i] == 0) pref[i]++;
  }
  for (int i(n); i >= 1; --i) {
    suf[i] = suf[i + 1];
    if (a[i] == 0) suf[i]++;
  }
  int ans = pref[n];
  for (int i(0); i < N; ++i) {
    if (g[i].size() == 0 || i == M) continue;
    int now = pref[g[i][0] - 1] + 1, l = 0;
    ans = max(ans, now + suf[g[i][0] + 1]);
    for (int j(1); j < int(g[i].size()); ++j) {
      int to = g[i][j];
      if (j - l < pref[to - 1] - pref[g[i][l] - 1]) {
        now = pref[to - 1] + 1;
        l = j;
      } else {
        now++;
      }
      ans = max(ans, now + suf[to + 1]);
    }
  }
  cout << ans << '\n';
  return 0;
}
