#include <bits/stdc++.h>
using namespace std;
vector<int> positions[500001];
int solve(int current, int c) {
  vector<int> howMany;
  int sum = 0;
  for (auto x : positions[current]) {
    int answer = -1;
    for (int power = 20; power >= 0; --power) {
      if (answer + (1 << power) < positions[c].size() and
          positions[c][answer + (1 << power)] < x) {
        answer += (1 << power);
      }
    }
    answer += 1;
    howMany.push_back(answer - sum);
    sum = answer;
  }
  howMany.push_back(positions[c].size() - sum);
  sum = 0;
  int totalMaxim = 0;
  int maximSoFar = 0;
  for (int i = 0; i < positions[current].size(); ++i) {
    sum += howMany[i];
    maximSoFar = max(maximSoFar, sum);
    maximSoFar += 1;
    totalMaxim = max(totalMaxim, maximSoFar + (int)(positions[c].size()) - sum);
  }
  return totalMaxim;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    positions[x].push_back(i);
  }
  int maximum = 0;
  for (int i = 1; i <= 500000; ++i) {
    if (i == c) {
      maximum = max(maximum, (int)positions[i].size());
    } else {
      maximum = max(maximum, solve(i, c));
    }
  }
  cout << maximum;
  return 0;
}
