#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int arr[maxn] = {};
int pref[maxn] = {};
int last[maxn] = {};
int kiek[maxn] = {};
int main() {
  int n, c;
  cin >> n >> c;
  cin >> arr[0];
  pref[0] += (arr[0] == c ? 1 : 0);
  for (int i = 1; i < n; ++i) {
    cin >> arr[i];
    pref[i] = pref[i - 1] + (arr[i] == c ? 1 : 0);
  }
  int mak = pref[n - 1];
  for (int i = 0; i < n; ++i) {
    int dbr = arr[i];
    if (dbr == c) continue;
    if (last[dbr] == 0) {
      last[dbr] = i + 1;
      kiek[dbr] = 1;
      mak = max(mak, pref[n - 1] + 1);
    } else {
      int pries = pref[last[dbr] - 1];
      int po = pref[n - 1] - pref[i];
      if (pref[n - 1] >= kiek[dbr] + pries + po) {
        last[dbr] = i + 1;
        kiek[dbr] = 1;
      } else
        ++kiek[dbr];
      mak = max(mak, pries + po + kiek[dbr]);
    }
  }
  cout << mak;
  return 0;
}
