#include <bits/stdc++.h>
using namespace std;
int a[5010];
int g[210][210];
int b[210];
bool v[210];
int from[210];
int e[210];
vector<int> h[210];
int bfs() {
  int where;
  queue<int> q;
  q.push(0);
  memset(v, 0, sizeof(v));
  v[0] = 1;
  memset(from, -1, sizeof(from));
  while (!q.empty()) {
    where = q.front();
    q.pop();
    for (int i = 0; i < 210; i++) {
      if (!v[i] && g[where][i] > 0) {
        q.push(i);
        v[i] = 1;
        from[i] = where;
        if (i == 209) goto outer;
      }
    }
  }
outer:
  where = 209;
  int pc = 10000000, pr;
  while (from[where] > -1) {
    pr = from[where];
    pc = min(pc, g[pr][where]);
    where = pr;
  }
  where = 209;
  while (from[where] > -1) {
    pr = from[where];
    g[pr][where] -= pc;
    g[where][pr] += pc;
    where = pr;
  }
  if (pc > 10000000 / 10) return 0;
  return pc;
}
int flow() {
  int f = 0;
  int cur = 0;
  while ((cur = bfs()) > 0) f += cur;
  return f;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == j) continue;
      g[i][103 + j] = 10000000;
    }
  }
  for (int i = 1; i <= m; i++) {
    g[0][i] = b[i];
    g[103 + i][209] = b[i];
  }
  int ans = flow();
  cout << ans << endl;
  for (int i = 103; i < 210; i++) {
    for (int j = 0; j < 103; j++) {
      while (g[i][j]-- > 0) h[j].push_back(i - 103);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
    if (e[a[i]] < h[a[i]].size()) {
      cout << h[a[i]][e[a[i]]];
      e[a[i]]++;
    } else
      cout << a[i];
    cout << endl;
  }
  return 0;
}
