#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
const long long int N = 5e5 + 5;
const long long int mod = 1e9 + 7;
const long long int inf = 1e18 + 9;
long long int a[N];
vector<long long int> v[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, c;
  cin >> n >> c;
  for (long long int i = 1; i <= n; i++) {
    long long int p;
    cin >> p;
    v[p].push_back(i);
    a[i] = a[i - 1] + (p == c);
  }
  long long int mx = 0;
  for (long long int i = 1; i < N; i++) {
    if (i == c || v[i].size() == 0) continue;
    long long int mi = 0;
    for (long long int j = 0; j < (long long int)v[i].size(); j++) {
      mi = min(mi, j - a[v[i][j] - 1]);
      mx = max(mx, j + 1 - a[v[i][j]] - mi);
    }
  }
  cout << a[n] + mx;
  return 0;
}
