#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
int n, C;
int a[MAXN];
int CCount = 0;
int answer = 0;
int current[MAXN], maxValue[MAXN], help[MAXN];
void resetSegment(int l, int r) {
  for (int i = l; i <= r; i++) {
    help[a[i]] = 0;
    current[a[i]] = 0;
    maxValue[a[i]] = 0;
  }
}
void solve(int l, int r) {
  if (l == r) {
    answer = max(answer, 1);
    return;
  }
  int mid = (l + r) / 2;
  int found = 0;
  resetSegment(l, r);
  for (int i = mid; i >= l; i--) {
    if (a[i] == C) found++;
    current[a[i]]++;
    maxValue[a[i]] = max(maxValue[a[i]], current[a[i]] - found);
  }
  found = 0;
  for (int i = mid + 1; i <= r; i++) {
    if (a[i] == C) found++;
    help[a[i]]++;
    answer = max(answer, CCount - found + help[a[i]] + maxValue[a[i]]);
  }
  found = 0;
  resetSegment(l, r);
  for (int i = mid + 1; i <= r; i++) {
    if (a[i] == C) found++;
    current[a[i]]++;
    maxValue[a[i]] = max(maxValue[a[i]], current[a[i]] - found);
  }
  found = 0;
  for (int i = mid; i >= l; i--) {
    if (a[i] == C) found++;
    help[a[i]]++;
    answer = max(answer, CCount - found + help[a[i]] + maxValue[a[i]]);
  }
  solve(l, mid);
  solve(mid + 1, r);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> C;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == C) CCount++;
  }
  solve(0, n - 1);
  cout << answer << '\n';
}
