#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 5;
vector<long long> g[N];
map<long long, long long> cnt;
long long n, c, a[N], pref[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> c;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    g[a[i]].push_back(i);
    pref[i] = pref[i - 1] + (a[i] == c);
  }
  long long ans = cnt[c];
  for (long long i = 1; i < N; i++) {
    if (!g[i].size() || i == c) continue;
    long long prev = g[i][0];
    long long cur = 0, max_so_far = 0;
    for (auto it : g[i]) {
      cur = cur + 1 - (pref[it] - pref[prev]);
      prev = it;
      if (cur <= 0) cur = 1;
      max_so_far = max(max_so_far, cur);
    }
    ans = max(ans, pref[n] + max_so_far);
  }
  cout << ans << endl;
  return 0;
}
