//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
struct Init { Init(){
    cin.tie(0); ios::sync_with_stdio(false);
} } init;
//}}}

ll n, x;
vector<ll> as;
unordered_map<ll, ll> memo[50];
ll solve(int idx, ll rem){
    if(idx == n - 1){
        return 1;
    }
    if(memo[idx].count(rem)){ return memo[idx][rem]; }
    ll rem2 = rem / as[idx + 1] * as[idx + 1];
    ll rem3 = (rem + as[idx + 1] - 1) / as[idx + 1] * as[idx + 1];
    // ll rem2 = rem - rem % as[idx + 1];
    ll ret = 0;
    if(rem != rem2){
        ret += solve(idx + 1, rem2);
    }
    ret += solve(idx + 1, rem3);
    printde(idx, rem, ret);
    return memo[idx][rem] = ret;
    // return ret;
}

int main(){
    cin >> n >> x;
    as.resize(n); cin >> as;
    ll ans = solve(0, x);
    cout << ans << '\n';
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
int a[maxn];
int b[maxn];
ll pre[maxn];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    sort(a+1,a+1+n);
    sort(b+1,b+1+m);
    for(int i=n;i;i--){
        if(i&1)pre[i]=pre[i+1]-a[i];
        else pre[i]=pre[i+1]+a[i];
    }
    int po=0;
    ll ans=LLONG_MAX,sum=0;
    for(int i=1;i<=m;i++){
        while(a[po+1]<=b[i]&&po<n){
            if(po&1)sum+=a[po+1];
            else sum-=a[po+1];
            po++;
            // cout<<po<<' '<<sum<<endl;
        }
        if(po&1)ans=min(sum+b[i]+abs(pre[po+1]),ans);
        else ans=min(sum-b[i]+abs(pre[po+1]),ans);
    }
    cout<<ans<<endl;
    return 0;
}
