#include <bits/stdc++.h>
using namespace std;
inline void sfr(int *a) {
  char c = 0;
  while (c < 33) c = fgetc(stdin);
  *a = 0;
  while (c > 33) {
    *a = *a * 10 + c - '0';
    c = fgetc(stdin);
  }
}
inline void sfp(int a) {
  char c[1000];
  sprintf(c, "%d", a);
  puts(c);
}
bool myfunc(pair<int, pair<int, int> > p1, pair<int, pair<int, int> > p2) {
  return p1 > p2;
}
vector<int> A[101];
int main() {
  int n;
  cin >> n;
  ;
  int m;
  cin >> m;
  ;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    ;
    A[c].push_back(i);
  }
  vector<pair<int, pair<int, int> > > B;
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < A[i].size(); j++) {
      B.push_back(make_pair(A[i].size(), make_pair(i, A[i][j])));
    }
  }
  int L[n], R[n];
  sort(B.begin(), B.end(), myfunc);
  int j = 0, i = 0;
  while ((i + 1) % n != 0) {
    i++;
    if (B[i].second.first != B[j].second.first) break;
  }
  int c = 0;
  while (j < n) {
    L[B[i].second.second] = B[i].second.first;
    R[B[i].second.second] = B[j].second.first;
    if (B[i].second.first != B[j].second.first) c++;
    i = (i + 1) % n;
    j++;
  }
  cout << c << endl;
  for (int i = 0; i < n; i++) cout << L[i] << " " << R[i] << endl;
}
