#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}
const int MAXN = 500100;
int n, m, ans;
int a[MAXN], p[MAXN], c[MAXN], f[MAXN];
vector<int> G[MAXN];
void Solve(int u) {
  int lst = G[u][0], t = 0, sum = 0;
  for (int i = 0; i < G[u].size() - 1; ++i) {
    if (G[u][i] != G[u][i + 1] - 1) {
      p[++t] = G[u][i] - lst + 1;
      if (i != G[u].size() - 2) p[++t] = -c[G[u][i + 1] - 1] + c[G[u][i]];
      lst = G[u][i + 1];
    }
  }
  f[0] = 0;
  for (int i = (1); i <= (t); ++i) {
    f[i] = max(f[i - 1], 0) + p[i];
    sum = max(sum, f[i]);
  }
  ans = max(ans, sum + c[n]);
}
int main() {
  rd(n), rd(m);
  for (int i = (1); i <= (n); ++i)
    rd(a[i]), c[i] = c[i - 1] + (a[i] == m), G[a[i]].push_back(i);
  for (int i = (1); i <= (500000); ++i) {
    if (G[i].size()) sort(G[i].begin(), G[i].end()), G[i].push_back(n + 2);
  }
  ans = c[n];
  for (int i = (1); i <= (500000); ++i)
    if (G[i].size() && i != m) Solve(i);
  printf("%d\n", ans);
  return 0;
}
