#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 50;
vector<int> vec[N];
int cnt[N], a[N], pre[N], sum[N], dp[N];
int main() {
  int n, c;
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    vec[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == c)
      sum[i] = sum[i - 1] + 1;
    else
      sum[i] = sum[i - 1];
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] == c)
      pre[i] = pre[i + 1] + 1;
    else
      pre[i] = pre[i + 1];
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int u = cnt[a[i]];
    if (cnt[a[i]] == 0) {
      dp[i] = sum[i - 1] + 1;
    } else {
      dp[i] = dp[vec[a[i]][u - 1]] + 1;
      dp[i] = max(sum[i - 1] + 1, dp[i]);
    }
    res = max(dp[i] + pre[i + 1], res);
    cnt[a[i]]++;
  }
  printf("%d\n", res);
}
