#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
queue<pair<int, int> > q;
map<int, bool> vis;
vector<int> v;
int main() {
  int n, m;
  cin >> n >> m;
  while (n--) {
    int t;
    cin >> t;
    vis[t] = 1;
    q.push({1, t + 1}), q.push({1, t - 1});
  }
  long long ans = 0;
  while (m > 0 && !q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    if (vis[cur.second] != 1) {
      m--;
      v.push_back(cur.second);
      ans += cur.first;
      vis[cur.second] = 1;
      if (vis[cur.second + 1] != 1) q.push({cur.first + 1, cur.second + 1});
      if (vis[cur.second - 1] != 1) q.push({cur.first + 1, cur.second - 1});
    }
  }
  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  return 0;
}
