#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
map<long long, long long> mp;
struct point {
  int pos, val;
  bool operator<(const point &x) const { return val > x.val; }
};
long long ans[200005], a[200005];
priority_queue<point> q;
int main() {
  long long n, m, t, sum, k;
  point temp;
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    mp[a[i]]++;
  }
  for (long long i = 1; i <= n; i++) {
    if (mp[a[i] - 1] == 0) {
      temp.pos = a[i] - 1;
      temp.val = 1;
      q.push(temp);
      mp[temp.pos]++;
    }
    if (mp[a[i] + 1] == 0) {
      temp.pos = a[i] + 1;
      temp.val = 1;
      q.push(temp);
      mp[temp.pos]++;
    }
  }
  sum = 0;
  k = 0;
  while (m--) {
    temp = q.top();
    q.pop();
    ans[++k] = temp.pos;
    sum += temp.val;
    point Next;
    if (mp[temp.pos - 1] == 0) {
      Next.pos = temp.pos - 1;
      Next.val = temp.val + 1;
      q.push(Next);
      mp[Next.pos]++;
    }
    if (mp[temp.pos + 1] == 0) {
      Next.pos = temp.pos + 1;
      Next.val = temp.val + 1;
      q.push(Next);
      mp[Next.pos]++;
    }
  }
  printf("%lld\n", sum);
  for (long long i = 1; i <= k; i++) {
    printf("%lld", ans[i]);
    if (i == k)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}
