#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int a[maxn], pre[maxn], last[maxn];
vector<int> v[maxn];
int cal(vector<int>& t) {
  int sum = 0, mx = 0;
  for (int i = 0; i < int(t.size()); ++i) {
    if (sum + t[i] <= 0)
      sum = 1;
    else
      sum += t[i];
    mx = max(mx, sum);
  }
  return mx;
}
int main() {
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pre[i] = a[i] == c ? pre[i - 1] + 1 : pre[i - 1];
    v[a[i]].push_back(1 - (pre[i - 1] - pre[last[a[i]]]));
    last[a[i]] = i;
  }
  int ans = 0;
  for (int i = 1; i < maxn; ++i)
    if (int(v[i].size()) && i != c) ans = max(ans, cal(v[i]));
  cout << ans + pre[n];
  return 0;
}
