#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> pref(n), a(n), dp(n), l((int)5e5 + 1, -1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    pref[i] = a[i] == k;
    pref[i] += i ? pref[i - 1] : 0;
  }
  auto get = [&](int l, int r) {
    return l > r ? 0 : pref[r] - (l ? pref[l - 1] : 0);
  };
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    dp[i] = get(0, i - 1) + 1;
    if (~l[a[i]]) {
      dp[i] = max(dp[i], dp[l[a[i]]] + 1);
    }
    l[a[i]] = i;
    ans = max(ans, dp[i] + get(i + 1, n - 1));
  }
  cout << ans;
  return 0;
}
