#include <bits/stdc++.h>
using namespace std;
int a[5000005];
int f[5000005];
int g[5000005];
int h[5000005];
int sum[5000005];
int last[5000005];
int n, c;
int main() {
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    sum[i] = sum[i - 1] + (a[i] == c);
    g[i] = 0;
  }
  int cc = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i] == a[i + 1]) {
      f[i] = f[i + 1] + 1;
    } else {
      f[i] = 1;
    }
    if (a[i] == c) {
      cc++;
    }
  }
  int idx = 1;
  memset(last, -1, sizeof(last));
  int res = 0;
  while (idx <= n) {
    if (a[idx] == c) {
    } else {
      res = max(res, f[idx]);
      if (last[a[idx]] != -1) {
        int tmp = h[last[a[idx]]] - (sum[idx] - sum[last[a[idx]] - 1]);
        h[idx] = tmp + f[idx];
        g[a[idx]] = min(g[a[idx]], tmp);
        res = max(res, h[idx] - g[a[idx]]);
      } else {
        h[idx] = f[idx];
      }
      last[a[idx]] = idx;
    }
    idx += f[idx];
  }
  cout << cc + res << endl;
  return 0;
}
