#include "bits/stdc++.h"
using namespace std;
#define ll long long

ll dp[5050][5050];
ll sdp[5050];
ll mod = 998244353;
ll invs[5050];
ll mis[5050][5050];

ll gcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int x = 0; x <= m; x++)
        {
            if (i > 0)
                mis[i][x] = mis[i - 1][x] * (m - x);
            else
                mis[i][x] = 1;
            mis[i][x] %= mod;
        }
    }
    for (int x = 1; x <= m; x++)
    {
        ll x1, y1;
        ll g = gcd(x, mod, x1, y1);
        x1 = (x1 % mod + mod) % mod;
        invs[x] = x1;
    }
    for (int i = 1; i <= m; i++)
    {
        dp[0][i] = 1;
    }
    sdp[0] = m;
    for (int i = 1; i < n; i++)
    {
        for (ll x = 1; x <= m; x++)
        {
            ll mi = mis[i][0];
            ll mix = mi - mis[i][x] + mod;
            mix %= mod;
            dp[i][x] = sdp[i - 1] + mi - (mix)*invs[x] + mod;
            dp[i][x] %= mod;
            sdp[i] += dp[i][x] + mod;
            sdp[i] %= mod;
        }
    }
    cout << sdp[n - 1] << endl;
    return 0;
}
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    unsigned N, M;
    scanf("%u %u", &N, &M);
    int H[N];
    for(unsigned i = 0; i < N; ++i){
        scanf("%d", H + i);
    }
    int W[M];
    for(unsigned i = 0; i < M; ++i){
        scanf("%d", W + i);
    }
    sort(H, H + N);
    sort(W, W + M);
    unsigned candidate = 0, answer = 999999999, id = 0, last;
    for (unsigned i = 0; i < N; i++){
        candidate += i&1 ? -H[i] : H[i];
    }
    for (unsigned i = 0; i < M && (!i || W[i-1] < H[N-1]); i++){
        last = id;
        id = distance(H, lower_bound(H, H + N, W[i]));
        for (unsigned j = last; j < id; j++){
            candidate += H[j]* ((j&1) ? 2 : -2); 
        }
        candidate = candidate - (i ? W[i-1] : 0)*((last&1) ? 1 : -1) + W[i]*((id&1) ? 1 : -1);
        if(answer > candidate) answer = candidate;
    }
    printf("%u\n", answer);
	return 0;
}