#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
long long mx[maxn], vis[maxn], pre[maxn], suf[maxn], a[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    suf[a[i]]++;
  }
  fill(mx, mx + maxn, -(1ll << 62));
  long long ans = suf[c] + (suf[c] != n);
  for (int i = 1; i <= n; i++) {
    pre[a[i]]++, suf[a[i]]--;
    if (a[i] != c && vis[a[i]]) {
      ans = max(ans, mx[a[i]] + pre[a[i]] + suf[c]);
    }
    if (a[i] != c) {
      vis[a[i]] = 1;
      mx[a[i]] = max(mx[a[i]], pre[c] - pre[a[i]] + 1);
    }
  }
  cout << ans << endl;
}
