#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  os << '{';
  string sep;
  for (const T &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
void dbg_out() { cerr << "\b\b]\n"; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << H << ", ";
  dbg_out(T...);
}
const int N = 500003;
vector<vector<int>> mp(N);
vector<int> last(N);
int tot = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, c;
  cin >> n >> c;
  vector<int> A(n), pref(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    tot += A[i] == c;
    pref[i] = A[i] == c;
    if (i) pref[i] += pref[i - 1];
  }
  auto qry = [&](int l, int r) {
    if (r < l) return 0;
    return pref[r] - (l ? pref[l - 1] : 0);
  };
  for (int i = 0; i < n; ++i) {
    mp[A[i]].push_back(-qry(last[A[i]], i));
    last[A[i]] = i;
    mp[A[i]].push_back(1);
  }
  auto kadane = [](vector<int> A) {
    int ans = -1e9, curr = 0;
    for (int i : A) {
      curr += i;
      ans = max(curr, ans);
      curr = max(0, curr);
    }
    return ans;
  };
  int ans = 0;
  for (int x = 1; x < N; ++x) {
    if (x == c) continue;
    ans = max(ans, kadane(mp[x]));
  }
  cout << ans + tot;
  return 0;
}
