#include <iostream>
using namespace std;

int main() {
    int a,b;cin>>a>>b;
    cout<<(a+b)/2<<" "<<(a-b)/2<<endl;
	return 0;
}
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;

double pi = 3.141592653589793238;
const ll LL_INF_BIG = 1e18 + 7;
const ll LL_INF = 1e9 + 7;
const int INF = 1e9 + 7;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template <class T> void chmin(T& a, T b) {
    if (a > b) a = b;
    return;
}

template <class T> void chmax(T& a, T b) {
    if (a < b) a = b;
    return;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
    vector<pair<ll, ll>> res;
    for (ll i = 2; i * i <= N; i++) {
        if (N % i != 0) continue;
        ll exp = 0;
        while (N % i == 0) {
            exp++;
            N /= i;
        }
        res.push_back({i, exp});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

ll mod_pow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll m) {
    ll b = m;
    ll u = 1;
    ll v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

const int MAX_COM = 10000000;
const int MOD = 1000000007;

ll fac[MAX_COM], finv[MAX_COM], inv[MAX_COM];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_COM; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
    vector<int> parents, siz;

    UnionFind(int N) : parents(N, -1), siz(N, 1) {}

    int root(int x) {
        if (parents.at(x) == -1) return x;
        return parents.at(x) = root(parents.at(x));
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (siz.at(rx) > siz.at(ry)) swap(rx, ry);
        parents.at(rx) = ry;
        // Update the size only at root.
        siz.at(ry) += siz.at(rx);
        return true;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    // If the size is needed, we need to see it at root.
    int size(int x) { return siz.at(root(x)); }
};

struct Edge {
    ll to;
    ll weight;
    Edge(ll t, ll w) : to(t), weight(w) {}
};

// using Edge = pair<int, pair<int, int>>; // w, u, v

using Graph = vector<vector<Edge>>;

Graph G;

vector<Edge> edge;

ll N,K;
vector<ll> A,CNT;

ll answer;
vector<ll> answers;

void input() {
    cin >> N >> K;
    A.resize(N);
    CNT.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
}

void solve() {
    for (int i = 0; i < N; i++) CNT[A[i]]++;

    for (int i = 0; i < N; i++) {
        if(CNT[i] < K) {
            ll dif = K - CNT[i];
            answer += i * (dif);
            K -= dif;
            if (K == 0) break;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    input();
    solve();
    // cout << fixed << setprecision(15);
    cout << answer << "\n";
    // for (auto answer : answers) cout << answer << "\n";
    return 0;
}
