#include <bits/stdc++.h>
using namespace std;
int N, M;
int color[101];
int graph[202][202];
vector<pair<int, int> > ans;
int source = 0, sink = 201;
int netflow() {
  int maxflow = 0;
  int memo[202];
  for (;;) {
    for (int i = 0; i < 202; ++i) memo[i] = -1;
    queue<int> Q;
    int top, flow = 0;
    bool found = 0;
    Q.push(source);
    memo[source] = source;
    while (!Q.empty()) {
      top = Q.front();
      Q.pop();
      if (top == sink) {
        found = 1;
        break;
      }
      for (int i = 0; i < 202; ++i) {
        if (memo[i] == -1 && graph[top][i] > 0) {
          Q.push(i);
          memo[i] = top;
        }
      }
    }
    if (found) {
      flow = 1000000;
      top = sink;
      while (top != source) {
        flow = min(flow, graph[memo[top]][top]);
        top = memo[top];
      }
      top = sink;
      while (top != source) {
        graph[memo[top]][top] -= flow;
        graph[top][memo[top]] += flow;
        top = memo[top];
      }
      maxflow += flow;
    } else
      break;
  }
  return maxflow;
}
int main() {
  int tmp;
  scanf("%d %d", &N, &M);
  memset(color, 0, sizeof(color));
  memset(graph, 0, sizeof(graph));
  for (int i = 0; i < N; ++i) {
    scanf("%d", &tmp);
    color[tmp]++;
  }
  for (int i = 1; i <= 100; ++i) {
    graph[0][i] = color[i];
  }
  for (int i = 1; i <= 100; ++i) {
    for (int j = 1; j <= 100; ++j) {
      if (i != j) graph[i][j + 100] = 1000000;
    }
  }
  for (int i = 1; i <= 100; ++i) {
    graph[i + 100][201] = color[i];
  }
  for (int i = 1; i <= M; ++i) color[i] *= 2;
  int ret = netflow();
  cout << ret << endl;
  for (int i = 1; i <= 100; ++i) {
    for (int j = 101; j <= 200; ++j) {
      if (graph[j][i] > 0) {
        for (int k = 0; k < graph[j][i]; ++k) {
          printf("%d %d\n", i, j - 100);
          color[i]--;
          color[j - 100]--;
        }
      }
    }
  }
  for (int i = 1; i <= M; ++i) {
    if (color[i] > 0) {
      for (int j = 0; j < color[i] / 2; ++j) printf("%d %d\n", i, i);
    }
  }
  return 0;
}
