#include <bits/stdc++.h>
using namespace std;
struct people {
  int coor = 0;
  int dis = 0;
};
queue<people> q;
map<people, bool> mp;
int n, m, a[200010];
long long total = 0;
vector<int> ans;
bool operator<(people a, people b) { return a.coor < b.coor; }
people ms(int coor, int dis) {
  people temp;
  temp.coor = coor;
  temp.dis = dis;
  return temp;
}
int main() {
  cin >> n >> m;
  for (int(i) = (0); (i) <= (n - 1); ++(i)) {
    int rd;
    cin >> rd;
    people temp = ms(rd, 0);
    q.push(temp);
    mp[temp] = 1;
  }
  while ((!q.empty()) && (ans.size() < m)) {
    people head = q.front();
    q.pop();
    if (head.dis != 0) {
      total += head.dis;
      ans.push_back(head.coor);
    }
    people toLeft = ms(head.coor - 1, head.dis + 1);
    people toRight = ms(head.coor + 1, head.dis + 1);
    if (mp[toLeft] != 1) {
      mp[toLeft] = 1;
      q.push(toLeft);
    }
    if (mp[toRight] != 1) {
      mp[toRight] = 1;
      q.push(toRight);
    }
  }
  cout << total << endl;
  for (int(i) = (0); (i) <= (m - 1); ++(i))
    cout << ans[i] << ((i == m - 1) ? "\n" : " ");
  return 0;
}
