#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e6 + 10;
const int inf = (int)2e9;
vector<int> v[N];
int n, c, sum = 0;
int main() {
  scanf("%d %d", &n, &c);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    v[x].push_back(i);
    if (x == c) sum += 1;
  }
  int answer = 0;
  for (int i = 1; i <= (int)5e5; i++) {
    if (i == c) continue;
    if (v[c].size() == 0) {
      answer = max(answer, (int)v[i].size());
      continue;
    }
    int len = (int)v[i].size();
    int cnt = 0;
    for (int j = 0; j < len; j++) {
      if (j == 0) {
        cnt += 1;
        answer = max(answer, sum + cnt);
      } else {
        int a =
            lower_bound(v[c].begin(), v[c].end(), v[i][j - 1]) - v[c].begin();
        int b = lower_bound(v[c].begin(), v[c].end(), v[i][j]) - v[c].begin();
        cnt -= (b - a);
        if (cnt < 0) cnt = 0;
        cnt += 1;
        answer = max(answer, sum + cnt);
      }
    }
  }
  answer = max(answer, sum);
  printf("%d\n", answer);
  return 0;
}
