#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = std::tuple<int, int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1},
          dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int N, C;
int A[500100];
int cnt[500100], cnt2[500100], nxt[500100];
int dp[500100];
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> N >> C;
  for (int i = 1; i <= N; ++i) {
    std::cin >> A[i];
  }
  for (int i = 1; i <= N; ++i) {
    cnt[i] = cnt[i - 1] + (A[i] == C);
  }
  for (int i = N; i >= 1; --i) {
    cnt2[i] = cnt2[i + 1] + (A[i] == C);
  }
  memset(nxt, -1, sizeof(nxt));
  for (int i = N; i >= 1; --i) {
    int a = A[i];
    if (nxt[a] == -1) {
      dp[i] = 1 + cnt2[i + 1];
      nxt[a] = i;
      continue;
    }
    dp[i] = std::max(1 + cnt2[i + 1], 1 + dp[nxt[a]]);
    nxt[a] = i;
  }
  int res = cnt[N];
  for (int i = 1; i <= N; ++i) {
    res = std::max(res, cnt[i - 1] + dp[i]);
  }
  std::cout << res << std::endl;
}
