#include <bits/stdc++.h>
using namespace std;
int n, c;
map<int, int> mp;
vector<int> cnt, a, dp;
int get_cnt(int l, int r) { return cnt[r] - (l > 0 ? cnt[l - 1] : 0); }
int main() {
  cin >> n >> c;
  a.assign(n, 0);
  cnt.assign(n, 0);
  dp.assign(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[i] = (i > 0 ? cnt[i - 1] : 0) + (a[i] == c ? 1 : 0);
  }
  int res = 0;
  int cnt_c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == c) cnt_c++;
  }
  for (int i = 0; i < n; i++) {
    dp[i] = (a[i] == c ? 0 : 1);
    res = max(res, cnt_c + dp[i]);
    if (a[i] == c) continue;
    if (mp.count(a[i])) {
      int j = mp[a[i]];
      dp[i] = max(dp[i], dp[j] + 1 - get_cnt(j + 1, i));
    }
    res = max(res, cnt_c + dp[i]);
    mp[a[i]] = i;
  }
  cout << res;
  return 0;
}
