//#define _GLIBCXX_DEBUG
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")

#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
using ll = long long;
#define int ll
using namespace std;
//using namespace __gnu_pbds;
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
//mt19937 mt(52);
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(auto &el : a) cin >> el;
    int p=0, q=0;
    sort(a.begin(), a.end());
    if(a[0] == a.back()){
        if(n <= m)cout << (n-1)*a[0]+((m-n+1)&1)*a[0]; else cout << m*a[0];
        return;
    }
    for(auto &el : a) if(el == a[0]) ++p; else ++q;
    vector<int> ans(n);
    for(int i=0; i<n-1; ++i) {
        if(q){
            ans[i] = a.back();
            --q;
        } else if(p){
            ans[i] = a[0];
            --p;
        }
    }
        for(int i=0; p+q; ++i){
            if(i&1 == 0){
                if(q){
                    ans.back() += a.back();
                    --q;
                }else if(p){
                    ans.back() += a[0];
                    --p;
                }
            } else{
                if(p){
                    ans.back() += a[0];
                    --p;
                }else if(q){
                    ans.back() += a.back();
                    --q;
                }
            }
        }
    int aans = 0;
    for(auto &el : ans) aans += el;
    cout << aans;
}


signed main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    bool cfmode = (42);
    if(cfmode){
        int t;
        cin >> t;
        while(t--){
            solve();
            cout << '\n';
        }
    } else solve();
}