#include <bits/stdc++.h>
using namespace std;
void fastInOut();
const int d[] = {-1, 1};
int n, m, x;
priority_queue<pair<int, int> > Q;
set<int> vis;
vector<int> ret;
long long solve() {
  long long tot = 0;
  while (m) {
    pair<int, int> cur = Q.top();
    Q.pop();
    if (vis.find(cur.second) != vis.end()) continue;
    --m, vis.insert(cur.second);
    tot += -cur.first, ret.push_back(cur.second);
    for (int i = 0; i < 2; ++i)
      if (vis.find(cur.second + d[i]) == vis.end())
        Q.push({cur.first - 1, cur.second + d[i]});
  }
  return tot;
}
int main() {
  fastInOut();
  cin >> n >> m;
  while (n--) {
    cin >> x, vis.insert(x);
    Q.push({-1, x - 1}), Q.push({-1, x + 1});
  }
  cout << solve() << "\n";
  sort(ret.begin(), ret.end());
  for (int i = 0; i < int(ret.size()); ++i)
    cout << ret[i] << " \n"[i == int(ret.size()) - 1];
  return 0;
}
void fastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
