#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
const int maxn=2e5+5,P=998244353;
int f[maxn],g[maxn];
int p[maxn],r;
int v[maxn],inv[25];
signed main(){
	int n=read(),m=read(),ans=1;
	inv[1]=1;
	for(register int i=2;i<=20;++i){
		inv[i]=1ll*inv[P%i]*(P-P/i)%P;
	}
	for(register int i=2,t;i<=m;++i){
		if(!v[i]){
			f[i]=n,g[i]=1,p[++r]=i;
		}
		for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){
			v[t]=1;
			if(i%p[j]){
				f[t]=1ll*f[i]*n%P,g[t]=1;
			}
			else{
				f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1;
				break;
			}
		}
		ans+=f[i];
		(ans>=P)&&(ans-=P);
	}
	printf("%d\n",ans);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll H[200005];
ll W[200005];
ll SUM[200005];
int main() {
    ll N, M;
    cin >> N >> M;
    rep(i, N)cin >> H[i];
    rep(i, M)cin >> W[i];
    sort(H, H + N);
    sort(W, W + M);
    
    SUM[N] = SUM[N - 1] = 0;
    for (int i = N - 2; i >= 0; i--)
    SUM[i] = SUM[i + 2] + H[i + 1] - H[i];
    
    //rep(i, M){
    //    cout << i << " " << W[i] << endl;
        //cout << i << " " << SUM[i] << endl;
    //}
    ll ans = 1e17;
    
    if (N == 1){
        rep(j, M)chmin(ans, abs(W[j] - H[0]));
        cout << abs(ans);
        return 0;
    }
    
    ll a = SUM[0];
    
    if (W[0] >= H[N - 1]){
        cout << a + W[0] - H[N - 1];
        return 0;
    }

        
    
    rep(j, M){
        if (W[j] >= H[N - 1]){
            chmin(ans, a + W[j] - H[N - 1]);
            continue;
        }
        
        int i = lower_bound(H, H + N, W[j]) - H;
        ll x;
        if (i == N - 1){
            x = a + H[i] - W[j];
            chmin(ans, x);
        } else if (i %2 == 0){
            x = a + H[i] - W[j] + SUM[i + 1] - SUM[i];
            chmin(ans, x);
        } else {
            x = a - (H[i] - W[j]) + SUM[i] - SUM[i + 1];
            chmin(ans, x);
        }
        //cout << "hoge "  << H[i] << " " << W[j] << " " << i << " " << x << endl;
    }
    cout << abs(ans);
    
}