#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
map<long long, bool> visted;
queue<long long> record[2];
vector<long long> ans;
int n, m;
long long getAns() {
  long long tmp;
  int num = 0;
  int index = 0;
  long long length = 0;
  int ccnt = 1;
  while (num < m) {
    while (!record[index].empty()) {
      tmp = record[index].front();
      record[index].pop();
      if (visted[tmp + 1] == 0) {
        num++;
        visted[tmp + 1] = 1;
        length += ccnt;
        ans.push_back(tmp + 1);
        record[index ^ 1].push(tmp + 1);
        if (num == m) return length;
      }
      if (visted[tmp - 1] == 0) {
        num++;
        visted[tmp - 1] = 1;
        length += ccnt;
        ans.push_back(tmp - 1);
        record[index ^ 1].push(tmp - 1);
        if (num == m) return length;
      }
    }
    ccnt++;
    index ^= 1;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int tmp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    record[0].push(tmp);
    visted[tmp] = 1;
  }
  printf("%lld\n", getAns());
  for (int i = 0; i < m; i++) {
    printf("%lld ", ans[i]);
  }
  return 0;
}
