#include <bits/stdc++.h>
using namespace std;
struct Position {
  int pos, r;
};
int arr[200005];
int ans[200005];
queue<Position> que;
map<int, bool> used;
long long cost = 0;
void solve(int m) {
  int cnt = 0;
  Position tmp;
  while (cnt < m) {
    tmp = que.front();
    que.pop();
    cost += tmp.r;
    ans[cnt++] = tmp.pos;
    tmp.r++;
    if (used[tmp.pos + 1] == 0) {
      used[tmp.pos + 1] = 1;
      tmp.pos++;
      que.push(tmp);
    } else if (used[tmp.pos - 1] == 0) {
      used[tmp.pos - 1] = 1;
      tmp.pos--;
      que.push(tmp);
    }
  }
}
int main() {
  int n, m;
  Position tmp;
  scanf("%d%d", &n, &m);
  tmp.r = 1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    used[arr[i]] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (used[arr[i] + 1] == 0) {
      used[arr[i] + 1] = 1;
      tmp.pos = arr[i] + 1;
      que.push(tmp);
    }
    if (used[arr[i] - 1] == 0) {
      used[arr[i] - 1] = 1;
      tmp.pos = arr[i] - 1;
      que.push(tmp);
    }
  }
  solve(m);
  printf("%I64d\n", cost);
  for (int i = 0; i < m; i++) printf("%d ", ans[i]);
  return 0;
}
