#include <bits/stdc++.h>
using namespace std;
int N, C;
int a[500500];
vector<int> p[500500];
int pr[500500];
int l[500500];
int mi, ma, ans;
int main() {
  cin >> N >> C;
  for (int i = 0; i < 500500; i++) {
    p[i].push_back(0);
    l[i] = 0;
  }
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    pr[i] = pr[i - 1] + (a[i] == C);
    p[a[i]].push_back(p[a[i]][p[a[i]].size() - 1] + 1 - pr[i] + pr[l[a[i]]]);
    l[a[i]] = i;
  }
  for (int i = 0; i < 500500; i++) {
    ma = -500500;
    if (p[i].size() > 1 && i != C) {
      for (int j = p[i].size() - 1; j > 0; j--) {
        ma = max(ma, p[i][j]);
        ans = max(ans, ma - p[i][j] + 1);
      }
    }
  }
  cout << ans + pr[N] << endl;
}
