#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr ll INF = 2e18;
constexpr ld EPS = 1e-9;
constexpr int MOD = 1000000007;
template <typename T1, typename T2>
istream &operator>>(istream &istream, pair<T1, T2> &p) {
  istream >> p.first >> p.second;
  return istream;
}
template <typename T>
istream &operator>>(istream &istream, vector<T> &v) {
  for (auto &it : v) cin >> it;
  return istream;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &ostream, const pair<T1, T2> &p) {
  ostream << p.first << " " << p.second;
  return ostream;
}
template <typename T>
ostream &operator<<(ostream &ostream, const vector<T> &c) {
  for (auto &it : c) cout << it << " ";
  return ostream;
}
template <typename T>
T MIN(T first) {
  return first;
}
template <typename T, typename... Args>
T MIN(T first, Args... args) {
  return min(first, MIN(args...));
}
template <typename T>
T MAX(T first) {
  return first;
}
template <typename T, typename... Args>
T MAX(T first, Args... args) {
  return max(first, MAX(args...));
}
template <typename T>
void print(T &&t) {
  cout << t << "\n";
}
template <typename T, typename... Args>
void print(T &&t, Args &&...args) {
  cout << t << " ";
  print(forward<Args>(args)...);
}
template <typename T>
int32_t size_i(T &container) {
  return static_cast<int32_t>(container.size());
}
long long GCD(long long a, long long b) {
  if (!b) return a;
  return GCD(b, a % b);
}
long long LCM(long long a, long long b) { return (a * b) / GCD(a, b); }
long long modpow(long long x, long long n, long long m = MOD) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = (res * x) % m;
    x = (x * x) % m;
    n >>= 1;
  }
  return res;
}
long long binpow(long long x, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x;
    x = (x * x);
    n >>= 1;
  }
  return res;
}
long long modinv(long long x, long long m = MOD) { return modpow(x, m - 2, m); }
void preSolve() {}
void solve(long long tc) {
  long long n, c;
  cin >> n >> c;
  vector<long long> a(n);
  cin >> a;
  vector<long long> pre(n), suf(n + 1);
  pre[0] = (a[0] == c);
  for (long long i = 1; i < n; i++) pre[i] = pre[i - 1] + (a[i] == c);
  for (long long i = n - 1; i >= 0; i--) suf[i] = suf[i + 1] + (a[i] == c);
  map<long long, vector<long long>> occ;
  for (long long i = 0; i < n; i++) occ[a[i]].push_back(i);
  long long ans = 0;
  for (auto &[num, v] : occ) {
    if (num == c) continue;
    vector<long long> b;
    b.push_back(1);
    for (long long i = 1; i < v.size(); i++) {
      b.push_back(-(suf[0] - suf[v[i]] - pre[v[i - 1]]));
      b.push_back(1);
    }
    long long msf = 0, meh = 0;
    for (auto &num : b) {
      meh += num;
      meh = max(0LL, meh);
      msf = max(msf, meh);
    }
    ans = max(ans, msf);
  }
  cout << suf[0] + ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(12) << fixed;
  preSolve();
  long long tests = 1;
  for (long long t = 1; t <= tests; t++) solve(t);
  return 0;
}
