#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
int sum[MAXN], minn[MAXN], cnt[MAXN], dp[MAXN], a[MAXN];
int main(void) {
  int n, c;
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + (a[i] == c);
  }
  for (int i = 1; i <= n; i++) {
    minn[a[i]] = min(minn[a[i]], cnt[a[i]] - sum[i - 1]);
    cnt[a[i]]++;
    dp[a[i]] = max(dp[a[i]], cnt[a[i]] - sum[i] - minn[a[i]]);
  }
  int ans = 0;
  for (int i = 1; i <= 5e5; i++) {
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans + sum[n]);
}
