#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = false;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = true;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
pair<int, int> t[500005];
int a[500005];
int pre[500005], aft[500005];
int n, c, kq;
int main() {
  read(n);
  read(c);
  int i;
  for (i = 1; i <= n; i++) {
    read(a[i]);
    t[i] = make_pair(a[i], i);
  }
  pre[0] = 0;
  for (i = 1; i <= n; i++) {
    pre[i] = pre[i - 1];
    if (a[i] == c) pre[i]++;
  }
  aft[n + 1] = 0;
  for (i = n; i >= 1; i--) {
    aft[i] = aft[i + 1];
    if (a[i] == c) aft[i]++;
  }
  kq = pre[n];
  sort(t + 1, t + n + 1);
  t[0] = make_pair(-1, -1);
  int x, tmp, startPos, endPos, dm;
  for (i = 1; i <= n; i++) {
    if (t[i].first != t[i - 1].first) {
      startPos = t[i].second;
      endPos = t[i].second;
      x = i;
      dm = 0;
    } else {
      endPos = t[i].second;
      dm++;
      if ((pre[t[i].second] - pre[startPos]) > dm) {
        dm = 0;
        x = i;
        startPos = t[i].second;
      }
    }
    tmp = (i - x + 1) + pre[startPos - 1] + aft[endPos + 1];
    kq = max(kq, tmp);
  }
  writeln(kq);
  return 0;
}
