#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 50;
int num[MAXN], sum[MAXN];
int dp[MAXN];
vector<int> pos[MAXN];
int main() {
  int n, c;
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  for (int i = 1; i <= n; i++) pos[num[i]].push_back(i);
  sum[0] = 0;
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (num[i] == c ? 1 : 0);
  int ans = 0;
  for (int r = 1; r <= 5e5; r++) {
    if (r == c || pos[r].size() == 0) continue;
    dp[pos[r][0]] = 1;
    ans = max(1, ans);
    for (int i = 1, l = pos[r].size(); i < l; i++) {
      int now = pos[r][i], prev = pos[r][i - 1];
      dp[now] = max(1, dp[prev] + 1 - (sum[now] - sum[prev]));
      ans = max(ans, dp[now]);
    }
  }
  printf("%d\n", ans + sum[n]);
  return 0;
}
