#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > ad(500005);
int dp[500005];
int main() {
  int n, c, a, i, j, m, x;
  scanf("%d%d", &n, &c);
  vector<int> v(n);
  for (i = 0; i < n; i++) scanf("%d", &v[i]);
  x = 0;
  for (i = 0; i < n; i++) {
    if (v[i] == c)
      x++;
    else {
      a = v[i];
      ad[a].push_back(x);
    }
  }
  int ans = x;
  for (i = 1; i < 500005; i++) {
    m = ad[i].size();
    if (m > 0) {
      dp[0] = 1, a = 1;
      for (j = 1; j < m; j++)
        dp[j] = max(1, dp[j - 1] + 1 - ad[i][j] + ad[i][j - 1]),
        a = max(a, dp[j]);
      ans = max(ans, x + a);
    }
  }
  printf("%d\n", ans);
}
