#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, m, c[101] = {0};
  cin >> n >> m;
  vector<pair<int, int> > arr, ans;
  for (i = 0; i < n; i++) {
    cin >> j;
    c[j]++;
  }
  for (i = 1; i <= m; i++) arr.push_back(make_pair(c[i], i));
  sort(arr.begin(), arr.end());
  for (i = 0; i < m - 1; i++) {
    j = min(arr[i].first, arr[i + 1].first);
    for (k = 0; k < j; k++) {
      ans.push_back(make_pair(arr[i].second, arr[i + 1].second));
      ans.push_back(make_pair(arr[i + 1].second, arr[i].second));
    }
    arr[i].first -= j;
    arr[i + 1].first -= j;
  }
  j = arr[m - 1].first;
  k = arr[m - 1].second;
  arr.clear();
  for (i = 0; i < ans.size(); i++) {
    if (ans[i].first != k && ans[i].second != k && j > 0) {
      arr.push_back(make_pair(ans[i].first, k));
      arr.push_back(make_pair(k, ans[i].second));
      j--;
    } else
      arr.push_back(make_pair(ans[i].first, ans[i].second));
  }
  cout << n - j << endl;
  for (i = 0; i < arr.size(); i++)
    cout << arr[i].first << " " << arr[i].second << endl;
  for (i = 0; i < j; i++) cout << k << " " << k << endl;
  return 0;
}
