#include <bits/stdc++.h>
using namespace std;
const long long N = 200000 + 10;
long long n, m, w[N], st[N], ans;
set<int> p;
struct node {
  long long bh, dis, wei;
  bool operator<(const node a) const { return a.dis < dis; }
} t, base;
priority_queue<node> pls;
int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &w[i]);
    p.insert(w[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (!p.count(w[i] - 1)) {
      base.bh = i;
      base.dis = 1;
      base.wei = w[i] - 1;
      pls.push(base);
      p.insert(w[i] - 1);
    }
    if (!p.count(w[i] + 1)) {
      base.bh = i;
      base.dis = 1;
      base.wei = w[i] + 1;
      pls.push(base);
      p.insert(w[i] + 1);
    }
  }
  for (int i = 1; i <= m; i++) {
    t = pls.top();
    pls.pop();
    st[i] = t.wei;
    ans += t.dis;
    if (!p.count(w[t.bh] - (t.dis + 1))) {
      base.bh = t.bh;
      base.dis = t.dis + 1;
      base.wei = w[t.bh] - (t.dis + 1);
      pls.push(base);
      p.insert(w[t.bh] - (t.dis + 1));
    }
    if (!p.count(w[t.bh] + (t.dis + 1))) {
      base.bh = t.bh;
      base.dis = t.dis + 1;
      base.wei = w[t.bh] + (t.dis + 1);
      pls.push(base);
      p.insert(w[t.bh] + (t.dis + 1));
    }
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= m; i++) printf("%lld ", st[i]);
  return 0;
}
