#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
const long long N = 5e5 + 5;
vector<long long> g[N];
long long p[N];
long long get(vector<long long>& v) {
  long long n = (long long)(v).size();
  if (n == 0) return 0;
  vector<long long> dp(n);
  dp[0] = max(0LL, v[0]);
  for (long long i = 1; i < (long long)n; i++)
    dp[i] = max(dp[i - 1] + v[i], v[i]);
  long long res = 0;
  for (long long i = 0; i < (long long)n; i++) res = max(res, dp[i]);
  return res;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  ;
  long long n, c, a;
  cin >> n >> c;
  for (long long i = 1; i < (long long)n + 1; i++) {
    cin >> a;
    p[i] = p[i - 1];
    if (a == c)
      p[i]++;
    else
      g[a].push_back(i);
  }
  long long ans = p[n];
  for (long long i = 1; i < (long long)N; i++)
    if ((long long)(g[i]).size() > 0) {
      vector<long long> v;
      v.push_back(1);
      for (long long j = 1; j < (long long)(long long)(g[i]).size(); j++) {
        long long l = g[i][j - 1];
        long long r = g[i][j];
        v.push_back(-(p[r] - p[l - 1]));
        v.push_back(1);
      }
      ans = max(ans, p[n] + get(v));
    }
  cout << ans << "\n";
}
