#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int n, m, ans, a[N], b[N], rep[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i], rep[a[i]]++;
  sort(a, a + n);
  copy(a, a + n, b);
  rotate(b, b + *max_element(rep, rep + m + 1), b + n);
  for (int i = 0; i < n; i++) ans += a[i] != b[i];
  cout << ans << '\n';
  for (int i = 0; i < n; i++) cout << a[i] << ' ' << b[i] << '\n';
  return 0;
}
