#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 6, mod = 1e9 + 7;
map<int, bool> used;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> v;
  set<pair<int, int>> s;
  for (int i = 0; i < (int)(n); ++i) {
    int x;
    cin >> x;
    used[x] = true;
    v.push_back(x);
  }
  for (auto &i : v) {
    if (!used[i + 1]) {
      s.insert({1, i + 1});
    }
    if (!used[i - 1]) {
      s.insert({1, i - 1});
    }
    used[i - 1] = used[i + 1] = 1;
  }
  long long dist = 0;
  vector<int> ans;
  while (m) {
    auto cur = *s.begin();
    s.erase(s.begin());
    dist += cur.first;
    ans.push_back(cur.second);
    if (!used[cur.second - 1]) {
      s.insert({cur.first + 1, cur.second - 1});
    }
    if (!used[cur.second + 1]) {
      s.insert({cur.first + 1, cur.second + 1});
    }
    used[cur.second - 1] = used[cur.second + 1] = 1;
    m--;
  }
  cout << dist << '\n';
  for (auto &i : ans) cout << i << ' ';
  return 0;
}
