#include <bits/stdc++.h>
using namespace std;
const int sz = 5e5 + 9;
int n, c, ans;
int a[sz], cs[sz];
vector<int> v[sz];
set<int> s;
int calc(int l, int r) {
  if (v[c].empty()) return 0;
  int st = 0, en = v[c].size() - 1;
  while (st < en) {
    int mid = (st + en) >> 1;
    if (v[c][mid] > l)
      en = mid;
    else
      st = mid + 1;
  }
  if (v[c][st] < l) return 0;
  int myl = st;
  st = 0, en = v[c].size() - 1;
  while (st < en) {
    int mid = (st + en + 1) >> 1;
    if (v[c][mid] < r)
      st = mid;
    else
      en = mid - 1;
  }
  if (v[c][st] > r) return 0;
  int myr = st;
  return myr - myl + 1;
}
int main() {
  scanf("%d %d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cs[i] = (a[i] == c);
    v[a[i]].push_back(i);
    s.insert(a[i]);
  }
  for (int i = 1; i <= n; i++) cs[i] += cs[i - 1];
  int all = cs[n];
  ans = all;
  for (auto u : s) {
    if (u == c) continue;
    int tmp = 0;
    int lst = -1;
    while (!v[u].empty()) {
      int curr = v[u].back();
      v[u].pop_back();
      if (~lst) {
        tmp -= calc(curr, lst);
        if (tmp < 0) tmp = 0;
      }
      tmp++;
      ans = max(ans, tmp + all);
      lst = curr;
    }
  }
  printf("%d", ans);
  return 0;
}
