#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto& x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, c;
  cin >> n >> c;
  vector<int> a(n + 1);
  vector<vector<int> > mp(5e5 + 1);
  vector<int> f(n + 1);
  for (auto i = (1); i <= (n); ++i) {
    cin >> a[i], mp[a[i]].push_back(i);
    if (a[i] == c) f[i]++;
    f[i] += f[i - 1];
  }
  int ans = f[n];
  for (auto i = (1); i <= (5e5); ++i)
    if (i != c and int(mp[i].size())) {
      int cur = 0, suff = 0;
      for (auto j = (0); j <= (int(mp[i].size()) - 1); ++j) {
        if (j) {
          int val = -f[mp[i][j]] + f[mp[i][j - 1]];
          suff = max(suff + val, val);
          cur = max(cur, suff);
        }
        int val = 1;
        suff = max(suff + val, val);
        cur = max(cur, suff);
      }
      ans = max(ans, f[n] + cur);
    }
  cout << ans;
  return 0;
}
