#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, c, a[N], dp[N], cnt[N], mx[N];
void readInput() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) cin >> a[i];
}
void solve() {
  for (int i = 0; i < n; i++) dp[c] += (a[i] == c);
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
    if (a[i] ^ c) {
      mx[a[i]] = max(mx[a[i]], cnt[c] - cnt[a[i]] + 1);
      dp[a[i]] = max(dp[a[i]], cnt[a[i]] + mx[a[i]] + dp[c] - cnt[c]);
    }
  }
}
void writeOutput() {
  int ans = 0;
  for (int i = 0; i < N; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  readInput(), solve(), writeOutput();
  return 0;
}
