#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int a[N];
int pre[N];
int dp[N];
map<int, int> cnt;
int main() {
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = pre[i - 1] + (a[i] == c);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    dp[a[i]] = max(dp[a[i]], pre[i - 1] - cnt[a[i]]);
    cnt[a[i]]++;
    ans = max(ans, dp[a[i]] + pre[n] + cnt[a[i]] - pre[i]);
  }
  cout << ans << endl;
  return 0;
}
