#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
vector<int> vec[N];
vector<int> tmp[N];
int BIT[N];
void upd(int idx) {
  for (; idx < N; idx += idx & -idx) BIT[idx]++;
}
int getAns(int idx) {
  int ans = 0;
  for (; idx; idx -= idx & -idx) ans += BIT[idx];
  return ans;
}
int get(int l, int r) { return getAns(r) - getAns(l - 1); }
int main() {
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == c)
      upd(i);
    else
      vec[x].push_back(i), tmp[x].push_back(i);
  }
  int ans = getAns(n);
  int old = ans;
  for (int i = 1; i < N; ++i) {
    if (i == c || vec[i].empty()) continue;
    for (int j = 0; j < vec[i].size(); ++j) {
      if (j == 0)
        tmp[i][j] = 0;
      else
        tmp[i][j] = -get(vec[i][j - 1], vec[i][j]);
    }
    int sum = 0;
    for (int j = 0; j < vec[i].size(); ++j) {
      sum += tmp[i][j];
      sum++;
      if (sum <= 0) sum = 1;
      ans = max(ans, old + sum);
    }
  }
  cout << ans << endl;
  return 0;
}
