#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, from;
};
queue<node> q;
map<int, bool> mp;
vector<int> vec;
int n, m;
int dir[2]{-1, 1};
long long bfs() {
  long long ans = 0;
  while (!q.empty()) {
    node st = q.front();
    q.pop();
    for (int i = 0; i < 2; i++) {
      node ne = {st.x + dir[i], st.from};
      if (mp[ne.x] == 0) {
        q.push(ne);
        vec.push_back(ne.x);
        mp[ne.x] = 1;
        ans += abs(ne.x - ne.from);
        if (vec.size() == m) return ans;
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    mp[x] = 1;
    q.push({x, x});
  }
  printf("%lld\n", bfs());
  int size = vec.size();
  for (int i = 0; i < size; i++) printf("%d ", vec[i]);
  printf("\n");
  return 0;
}
