#include <bits/stdc++.h>
using namespace std;
const long long maxn = 500000 + 5;
const long long inf = 9e17;
long long ans, dp[maxn];
vector<long long> adj[maxn];
long long a[maxn], prf[maxn], n, c;
int main() {
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    prf[i] = prf[i - 1] + (a[i] == c);
    adj[a[i]].push_back(i);
  }
  ans = min(prf[n] + 1, n);
  for (int i = 1; i < maxn; i++) {
    if (i == c) continue;
    if (adj[i].size() <= 1) continue;
    dp[0] = 0;
    for (int j = 1; j < adj[i].size(); j++) {
      dp[j] =
          max(2 - (prf[adj[i][j]] - prf[adj[i][j - 1] - 1]),
              dp[j - 1] + 2 - (prf[adj[i][j]] - prf[adj[i][j - 1] - 1]) - 1);
      ans = max(ans, dp[j] + prf[n]);
    }
  }
  cout << ans << "\n";
  return 0;
}
