#include <bits/stdc++.h>   using namespace std;   map<long long, long long> dist;   int main() {     long long n, m;     cin >> n >> m;     long long x;     queue<long long> q;     for (long long i = 0; i < n; i++) {       cin >> x;       dist[x] = 0;       q.push(x);     }     long long total = 0;     vector<long long> ans;     while (!q.empty()) {       x = q.front();       q.pop();       if (dist[x] != 0) {         ans.push_back(x);         total += (dist[x]);         if (ans.size() == m) break;       }       if (dist.find(x - 1) == dist.end()) {         q.push(x - 1);         dist[x - 1] = dist[x] + 1;       }       if (dist.find(x + 1) == dist.end()) {         q.push(x + 1);         dist[x + 1] = dist[x] + 1;       }     }     cout << total <<   n ;     for (long long i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }   