#include <bits/stdc++.h>
using namespace std;
struct Data {
  int pref, suf, ans, sum;
  Data() { pref = suf = ans = sum = -1000000000; }
  Data(int a, int b, int c, int d) {
    pref = a;
    suf = b;
    ans = c;
    sum = d;
  }
} temp;
Data seg[2000020];
int b[500050];
void Merge(Data &a, Data b, Data c) {
  a.ans = max(b.ans, c.ans);
  a.pref = max(b.pref, b.sum + c.pref);
  a.suf = max(c.suf, c.sum + b.suf);
  a.sum = b.sum + c.sum;
  a.ans = max(a.ans, b.suf + c.pref);
}
void build(int node, int l, int r) {
  if (l == r) {
    seg[node] = {b[l], b[l], b[l], b[l]};
    return;
  }
  int m = (l + r) / 2;
  build(2 * node + 1, l, m);
  build(2 * node + 2, m + 1, r);
  Merge(seg[node], seg[2 * node + 1], seg[2 * node + 2]);
}
Data qu(int node, int x, int y, int l, int r) {
  if (l > y or r < x) return temp;
  if (l >= x and r <= y) return seg[node];
  int m = (l + r) / 2;
  Data lt = qu(2 * node + 1, x, y, l, m);
  Data rt = qu(2 * node + 2, x, y, m + 1, r);
  Data ret;
  Merge(ret, lt, rt);
  return ret;
}
void upd(int node, int l, int r, int pos, int val) {
  if (l > pos or r < pos) return;
  if (l == r) {
    seg[node] = {val, val, val, val};
    return;
  }
  int m = (l + r) / 2;
  upd(2 * node + 1, l, m, pos, val);
  upd(2 * node + 2, m + 1, r, pos, val);
  Merge(seg[node], seg[2 * node + 1], seg[2 * node + 2]);
}
vector<vector<int>> place(500050);
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, c;
  cin >> n >> c;
  int a[n], ans = 0, final = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == c) {
      ++ans;
      b[i] = -1;
    } else {
      place[a[i]].push_back(i);
      b[i] = 0;
    }
  }
  final = ans;
  build(0, 0, n - 1);
  for (int i = 0; i < 500050; ++i) {
    if (place[i].empty()) continue;
    for (auto it : place[i]) upd(0, 0, n - 1, it, 1);
    auto get = qu(0, 0, n - 1, 0, n - 1);
    int cur = ans + get.ans;
    final = max(final, cur);
    for (auto it : place[i]) upd(0, 0, n - 1, it, 0);
  }
  cout << final;
}
