#include <bits/stdc++.h>
using namespace std;
const int M = 5e5;
const int N = M + 7;
int n, c, a[N];
vector<int> pos[N];
int main() {
  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cin >> n >> c;
  for (int i = 1; i <= n; ++i) {
    int value;
    cin >> value;
    a[i] = a[i - 1] + (value == c);
    pos[value].push_back(i);
  }
  int answer = max(1, min(n, a[n] + 1));
  for (int value = 1; value <= M; ++value)
    if (value != c && pos[value].size() >= 2) {
      int u = 0;
      for (int v = 1; v < (int)pos[value].size(); ++v) {
        while (a[pos[value][v]] - a[pos[value][u] - 1] >= (v - u + 1)) ++u;
        answer =
            max(answer, (v - u + 1) +
                            (a[n] - (a[pos[value][v]] - a[pos[value][u] - 1])));
      }
    }
  cout << answer << "\n";
  return 0;
}
