#include <bits/stdc++.h>
using namespace std;
int ai[500005];
vector<int> vc[500005];
int main() {
  int n, c;
  cin >> n >> c;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ai[i]);
    if (ai[i] == c) sum++;
    vc[ai[i]].push_back(i);
  }
  int ans = sum;
  for (int i = 1; i <= 500000; i++) {
    if (i == c) continue;
    if (vc[c].size() == 0) {
      int ln = vc[i].size();
      ans = max(ans, ln);
      continue;
    }
    int cur = 0;
    for (int j = 0; j < vc[i].size(); j++) {
      if (j == 0) {
        ans = max(ans, sum + 1);
        cur++;
      } else {
        int a = lower_bound(vc[c].begin(), vc[c].end(), vc[i][j - 1]) -
                vc[c].begin();
        int b =
            lower_bound(vc[c].begin(), vc[c].end(), vc[i][j]) - vc[c].begin();
        cur -= (b - a);
        if (cur < 0) cur = 0;
        cur++;
        ans = max(ans, sum + cur);
      }
    }
  }
  cout << ans;
}
