#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
int n, m, k, ar[maxn];
vector<int> ve[maxn];
int pre[maxn], mid[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", ar + i);
  for (int i = 1; i <= n; i++) {
    ve[ar[i]].push_back(i);
  }
  memset(pre, 0, sizeof(pre));
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (ar[i] == m);
  int ans = 0;
  for (int i = 1; i <= maxn; i++) {
    int mx = 0;
    for (int j = 0; j < ve[i].size(); j++) {
      mx = max(mx, pre[ve[i][j] - 1] + 1);
      ans = max(ans, mx + pre[n] - pre[ve[i][j]]);
      mx++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
