#include <bits/stdc++.h>
using namespace std;
int f[105];
vector<pair<int, int>> ans;
priority_queue<pair<int, int>> pq;
int main() {
  int n, m, x;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    f[x]++;
  }
  for (int i = 1; i <= m; i++)
    if (f[i] != 0) pq.push({f[i], i});
  if (n % 2 == 1) {
    auto x = pq.top();
    pq.pop();
    if (!pq.empty()) {
      auto y = pq.top();
      pq.pop();
      if (!pq.empty()) {
        auto z = pq.top();
        pq.pop();
        x.first--, y.first--, z.first--;
        f[x.second]--, f[y.second]--, f[z.second]--;
        ans.push_back({x.second, y.second});
        ans.push_back({y.second, z.second});
        ans.push_back({z.second, x.second});
        if (z.first != 0) pq.push(z);
      }
      if (y.first != 0) pq.push(y);
    }
    if (x.first != 0) pq.push(x);
  }
  while (!pq.empty()) {
    auto y = pq.top();
    pq.pop();
    if (pq.empty()) break;
    auto x = pq.top();
    pq.pop();
    x.first--;
    f[x.second]--;
    y.first--;
    f[y.second]--;
    if (x.first != 0) pq.push(x);
    if (y.first != 0) pq.push(y);
    ans.push_back({x.second, y.second});
    ans.push_back({y.second, x.second});
  }
  cout << ans.size() << "\n";
  for (auto x : ans) cout << x.first << " " << x.second << "\n";
  for (int i = 1; i <= m; i++)
    while (f[i]--) cout << i << " " << i << "\n";
  return 0;
}
