#include<bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmin(T &a,const T b){if(a>b){a=b; return true;}return false;}
template<typename T> bool chmax(T &a,const T b){if(a<b){a=b; return true;}return false;}


int main(){
    int n, m; cin >> n >> m;
    vector<ll> h(n), w(m);
    for(auto &x : h) cin >> x;
    for(auto &x : w) cin >> x;

    sort(all(h));
    int p=(n+1)/2;
    vector<ll> sl(p, 0), sr(p, 0);
    for(int i=0; i<p-1; i++){
        sl[i+1]=sl[i]+h[2*i+1]-h[2*i];
    }
    for(int i=p-1; i>=1; i--){
        sr[i-1]=sr[i]+h[2*i]-h[2*i-1];
    }

    ll ans=LINF;
    for(int i=0; i<m; i++){
        int id=lower_bound(all(h), w[i])-h.begin();
        ll sum;
        if(id%2 == 0){
            sum=sr[id/2]+h[id]-w[i]+sl[id/2];
            chmin(ans, sum);
        }
        else{
            sum=sr[(id-1)/2]+w[i]-h[id-1]+sl[(id-1)/2];
            chmin(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

bool less_size(string ls, string rs) {
  return ls.size() < rs.size();
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> s(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i];
  }
  
  sort(s.begin(), s.end(), less_size);
  int j = 0;
  for (int i = 0; i < N; i++) {
    int count = 0;
    while (j < M && count + s[j].size() <= 20) {
      count += s[j].size();
      cout << s[j];
      j++;
    }
    for (int k = count; k < N; k++) {
      cout << ".";
    }
    cout << endl;
  }
  return 0;
}