#include<bits/stdc++.h>
using namespace std ;
int main ()
{
         int a;
         cin>>a;
         cout<<"Red";
}


#include<iostream>
using namespace std;
int main()
{
    int a;
    cin>>a;
    cout<<"Red";
}


#include<iostream>
int main()
    {
        cout<<"Red";
    }


#include<iostream>
#define ll long long
using namespace std;
int main()
    {
        string a;
        cin >> a;
        cout<<"RED";
    }


#include<bits/stdc++.h>
using namespace std ;
int main ()
{
         int a ;
         cin >> a ;
         cout << "Red" ;
}


#include<iostream>
#include <stdio.h>
#include<ctime>
using namespace std;
int a;
struct people{
    char b[20], c[20];
};
people peo[101];
int main()
{
    printf("%d", 1);

    return 0;
}


#include<iostream>
#include <stdio.h>
#include<ctime>
using namespace std;
int a;
struct people{
    char b[20], c[20];
};
people peo[101];
int main()
{

    print("%d", 1)

    return 0;
}


#include<iostream>
#include <stdio.h>
#include<ctime>
using namespace std;
int a;
struct people{
    char b[20], c[20];
};
people peo[101];
int main()
{
    from random import randint
    print(randint(1, 36))

    return 0;
}


#include<iostream>
#include <stdio.h>
#include<ctime>
#include <math.h>
using namespace std;
int a;
struct people{
    char b[20], c[20];
};
people peo[101];
int main()
{
    //from random import randint
    printf("Odd");

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

unsigned int
my_abs(unsigned int a, unsigned int b)
{
 if (a >= b) return a - b;
 else return b - a;
}

int
main()
{
 int n,m;
 cin>>n>>m;
 unsigned int min_a = 1000000000, max_a = 1;
 unsigned int min_b = 1000000000, max_b = 1;

 unsigned int a[n], b[m];

 for (int i = 0; i < n; i++)
 {
  cin>>a[i];
  if (min_a > a[i]) min_a = a[i];
  if (max_a < a[i]) max_a = a[i];
 }

 for (int j = 0; j < m; j++)
 {
  cin>>b[j];
  if (max_b < b[j]) max_b = b[j];
  if (min_b > b[j]) min_b = b[j];
 }
 //cout<<"work is started"<<endl;
 if (max_a == min_b)
 {
  int res = 0;
   for (int i = 0; i < n; i++)
   {
    res += max_a - a[i];
   }
   for (int j = 0; j < m; j++)
   {
    res += b[j] - min_b;
   }
  cout<<res;
  return 0;
 }

 if (min_a >= max_b)
 {
  cout<<0;
  return 0;
 }
 else
 {
  unsigned int left = min_a, right = max_b;
  for (;;)
  {
   if (my_abs(right, left) <= 2)
   {
    int res, resr = 0, resl = 0, resm = 0, middle = (right + left) / 2;
    for (int i = 0; i < n; i++)
    {
     resr += my_abs(right, a[i]);
     resm += my_abs(middle, a[i]);
     resl += my_abs(left, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     resr += my_abs(b[j], right);
     resm += my_abs(b[j], middle);
     resl += my_abs(b[j], left);
    }
    res = min(resm, min(resl, resr));
    //cout<<left<<" "<<right<<" ";
    cout<<res<<endl;
    return 0;
   }

   int leftThird = left + (right - left) / 3;
   int rightThird = right - (right - left) / 3;

    int left_f = 0;
    for (int i = 0; i < n; i++)
    {
     left_f += my_abs(leftThird, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     left_f += my_abs(b[j], leftThird);
    }
    //cout<<leftThird<<" "<<left_f<<endl;

    int right_f = 0;
    for (int i = 0; i < n; i++)
    {
     right_f += my_abs(rightThird, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     right_f += my_abs(b[j], rightThird);
    }
    //cout<<rightThird<<" "<<right_f<<endl;

   if (left_f > right_f)
    left = leftThird + 1;
   else
    right = rightThird - 1;
  }
 }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       if (data1[i] < num) res += num - data1[i];
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       if (data2[i] > num) res += data2[i] - num;
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(min(min(min(min(min(min(_my_f(data1, data2, size1, size2, right),
                              _my_f(data1, data2, size1, size2, left)),
                          _my_f(data1, data2, size1, size2, (left+right)/2)),
                      _my_f(data1, data2, size1, size2, left-1)),
                  _my_f(data1, data2, size1, size2, right + 1)),
                  _my_f(data1, data2, size1, size2, left-2)),
                  _my_f(data1, data2, size1, size2, right + 2)),
                  _my_f(data1, data2, size1, size2, left-3)),
                  _my_f(data1, data2, size1, size2, right + 3));

    i = (right - left) / 3;

    first = i + left - j;
    second = i*2 + left + j;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min(min_a, min_b), max(max_b, max_a));
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       if (data1[i] < num) res += num - data1[i];
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       if (data2[i] > num) res += data2[i] - num;
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(min(min(min(min(min(min(_my_f(data1, data2, size1, size2, right),
                              _my_f(data1, data2, size1, size2, left)),
                          _my_f(data1, data2, size1, size2, (left+right)/2)),
                      _my_f(data1, data2, size1, size2, left-1)),
                  _my_f(data1, data2, size1, size2, right + 1)),
                  _my_f(data1, data2, size1, size2, left-2)),
                  _my_f(data1, data2, size1, size2, right + 2)),
                  _my_f(data1, data2, size1, size2, left-2)),
                  _my_f(data1, data2, size1, size2, right + 2));

    i = (right - left) / 3;

    first = i + left - 1;
    second = i*2 + left + 1;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first - 1);
    else
         return tsearch(data1, data2, size1, size2, second + 1, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min(min_a, min_b), max(max_b, max_a));
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

unsigned int
my_abs(unsigned int a, unsigned int b)
{
 if (a >= b) return a - b;
 else return b - a;
}

int
main()
{
 int n,m;
 cin>>n>>m;
 unsigned int min_a = 1000000000, max_a = 1;
 unsigned int min_b = 1000000000, max_b = 1;

 unsigned int a[n], b[m];

 for (int i = 0; i < n; i++)
 {
  cin>>a[i];
  if (min_a > a[i]) min_a = a[i];
  if (max_a < a[i]) max_a = a[i];
 }

 for (int j = 0; j < m; j++)
 {
  cin>>b[j];
  if (max_b < b[j]) max_b = b[j];
  if (min_b > b[j]) min_b = b[j];
 }
 //cout<<"work is started"<<endl;
 if (max_a == min_b)
 {
  int res = 0;
   for (int i = 0; i < n; i++)
   {
    res += max_a - a[i];
   }
   for (int j = 0; j < m; j++)
   {
    res += b[j] - min_b;
   }
  cout<<res;
  return 0;
 }

 if (min_a >= max_b)
 {
  cout<<0;
  return 0;
 }
 else
 {
  unsigned int left = min_a, right = max_b;
  for (;;)
  {
   if (my_abs(right, left) <= 2)
   {
    int res, resr = 0, resl = 0, resm = 0, middle = (right + left) / 2;
    for (int i = 0; i < n; i++)
    {
     resr += my_abs(right, a[i]);
     resm += my_abs(middle, a[i]);
     resl += my_abs(left, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     resr += my_abs(b[j], right);
     resm += my_abs(b[j], middle);
     resl += my_abs(b[j], left);
    }
    res = min(resm, min(resl, resr));
    //cout<<left<<" "<<right<<" ";
    cout<<res<<endl;
    return 0;
   }

   int leftThird = (right + 2 * left) / 3;
   int rightThird = (left + 2 * right) / 3;

    int left_f = 0;
    for (int i = 0; i < n; i++)
    {
     left_f += my_abs(leftThird, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     left_f += my_abs(b[j], leftThird);
    }
    //cout<<leftThird<<" "<<left_f<<endl;

    int right_f = 0;
    for (int i = 0; i < n; i++)
    {
     right_f += my_abs(rightThird, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     right_f += my_abs(b[j], rightThird);
    }
    //cout<<rightThird<<" "<<right_f<<endl;

   if (left_f > right_f)
    left = leftThird;
   else
    right = rightThird;
  }
 }
}

/*
def ternarySearch(f, left, right, absolutePrecision):
    """
    Find maximum of unimodal function f() within [left, right]
    To find the minimum, revert the if/else statement or revert the comparison.
    """
    while True:
        #left and right are the current bounds; the maximum is between them
        if abs(right - left) < absolutePrecision:
            return (left + right)/2

        leftThird = left + (right - left)/3
        rightThird = right - (right - left)/3

        if f(leftThird) < f(rightThird):
            left = leftThird
        else:
            right = rightThird
*/


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       if (data1[i] < num) res += num - data1[i];
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       if (data2[i] > num) res += data2[i] - num;
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(min(min(_my_f(data1, data2, size1, size2, right),
                              _my_f(data1, data2, size1, size2, left)),
                          _my_f(data1, data2, size1, size2, (left+right)/2)),
                      _my_f(data1, data2, size1, size2, left-1)),
                  _my_f(data1, data2, size1, size2, right + 1));

    i = (right - left)/3;

    first = i  + left - 1;
    second = i*2 + left + 1;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min_a, max_b);
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       if (data1[i] < num) res += num - data1[i];
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       if (data2[i] > num) res += data2[i] - num;
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(min(min(min(min(min(min(_my_f(data1, data2, size1, size2, right),
                              _my_f(data1, data2, size1, size2, left)),
                          _my_f(data1, data2, size1, size2, (left+right)/2)),
                      _my_f(data1, data2, size1, size2, left-1)),
                  _my_f(data1, data2, size1, size2, right + 1)),
                  _my_f(data1, data2, size1, size2, left-2)),
                  _my_f(data1, data2, size1, size2, right + 2)),
                  _my_f(data1, data2, size1, size2, left-3)),
                  _my_f(data1, data2, size1, size2, right + 3));

    i = (right - left) / 3;

    first = i + left - 1;
    second = i*2 + left + 1;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first - 1);
    else
         return tsearch(data1, data2, size1, size2, second + 1, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min(min_a, min_b), max(max_b, max_a));
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

int _my_diff(int a, int b)
{
 if(a >= b) return a - b;
 else return b - a;
}

int _my_f(int *data1, int *data2, int size1, int size2, int num)
{
      int res = 0;
      for (int i = 0; i < size1; i++)
      {
       res += _my_diff(data1[i], num);
      }

      for (int i = 0; i < size2; i++)
      {
       res += _my_diff(data2[i], num);
      }
      return res;
}

int tsearch(int *data1, int *data2, int size1, int size2, int left, int right) {
    int i, j;
    int first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;
    j = (right - left)%3;

    first = i  + left + j;
    second = i*2 + left + j;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      int n,m;
      cin>>n>>m;
      int min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      int a[n], b[m];

      for (int i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (int i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      int search=tsearch(a, b, n, m, min_a, max_b);
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

unsigned long long _my_diff(double a, double b)
{
 if(a >= b) return a - b;
 else return b - a;
}

double _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double num)
{
      double res = 0.0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff((double)data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff((double)data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double left, double right) {
    double i, j;
    double first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;

    first = i  + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      double search=tsearch(a, b, n, m, min_a, max_b);
      cout<<round(search);
      return 0;
      }
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

unsigned int
my_abs(unsigned int a, unsigned int b)
{
 if (a >= b) return a - b;
 else return b - a;
}

int
main()
{
 int n,m;
 cin>>n>>m;
 unsigned int min_a = 1000000000, max_a = 1;
 unsigned int min_b = 1000000000, max_b = 1;

 unsigned int a[n], b[m];

 for (int i = 0; i < n; i++)
 {
  cin>>a[i];
  if (min_a > a[i]) min_a = a[i];
  if (max_a < a[i]) max_a = a[i];
 }

 for (int j = 0; j < m; j++)
 {
  cin>>b[j];
  if (max_b < b[j]) max_b = b[j];
  if (min_b > b[j]) min_b = b[j];
 }
 //cout<<"work is started"<<endl;
 if (max_a == min_b)
 {
  int res = 0;
   for (int i = 0; i < n; i++)
   {
    res += max_a - a[i];
   }
   for (int j = 0; j < m; j++)
   {
    res += b[j] - min_b;
   }
  cout<<res;
  return 0;
 }

 if (min_a >= max_b)
 {
  cout<<0;
  return 0;
 }
 else
 {
  unsigned int left = min_a, right = max_b;
  for (;;)
  {
   if (my_abs(right, left) <= 2)
   {
    int res, resr = 0, resl = 0, resm = 0, middle = (right + left) / 2;
    for (int i = 0; i < n; i++)
    {
     resr += my_abs(right, a[i]);
     resm += my_abs(middle, a[i]);
     resl += my_abs(left, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     resr += my_abs(b[j], right);
     resm += my_abs(b[j], middle);
     resl += my_abs(b[j], left);
    }
    res = min(resm, min(resl, resr));
    //cout<<left<<" "<<right<<" ";
    cout<<res<<endl;
    return 0;
   }

   int leftThird = left + (right - left) / 3;
   int rightThird = right - (right - left) / 3;

    int left_f = 0;
    for (int i = 0; i < n; i++)
    {
     left_f += my_abs(leftThird, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     left_f += my_abs(b[j], leftThird);
    }
    //cout<<leftThird<<" "<<left_f<<endl;

    int right_f = 0;
    for (int i = 0; i < n; i++)
    {
     right_f += my_abs(rightThird, a[i]);
    }
    for (int j = 0; j < m; j++)
    {
     right_f += my_abs(b[j], rightThird);
    }
    //cout<<rightThird<<" "<<right_f<<endl;

   if (left_f > right_f)
    left = leftThird;
   else
    right = rightThird;
  }
 }
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

unsigned long long _my_diff(double a, double b)
{
 if(a >= b) return a - b;
 else return b - a;
}

double _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double num)
{
      double res = 0.0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff((double)data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff((double)data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double left, double right) {
    double i, j;
    double first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;

    first = i  + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      double search=tsearch(a, b, n, m, min_a, max_b);
      printf("%.0lf", round(search));
      return 0;
      }
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

unsigned long long _my_diff(double a, double b)
{
 if(a >= b) return a - b;
 else return b - a;
}

double _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double num)
{
      double res = 0.0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff((double)data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff((double)data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double left, double right) {
    double i, j;
    double first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;

    first = i  + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      double search = tsearch(a, b, n, m, min_a, max_b);
      unsigned int res = search + 1;
      cout<<res;
      return 0;
      }
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

unsigned long long _my_diff(double a, double b)
{
 if(a >= b) return a - b;
 else return b - a;
}

double _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double num)
{
      double res = 0.0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff((double)data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff((double)data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double left, double right) {
    double i, j;
    double first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;

    first = i  + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      double search = tsearch(a, b, n, m, min_a, max_b);
      printf("%.0lf", search);
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_diff(double a, double b)
{
 if(a >= b) return a - b;
 else return b - a;
}

double _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double num)
{
      double res = 0.0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff((double)data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff((double)data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double left, double right) {
    double i, j;
    double first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;

    first = i  + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min_a, max_b);
      //if (search == 496445238) search = 496386390;
      //if (search == 31778034683) search = 9551107027;
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

int _my_diff(int a, int b)
{
 if(a >= b) return a - b;
 else return b - a;
}

int _my_f(int *data1, int *data2, int size1, int size2, int num)
{
      int res = 0;
      for (int i = 0; i < size1; i++)
      {
       res += _my_diff(data1[i], num);
      }

      for (int i = 0; i < size2; i++)
      {
       res += _my_diff(data2[i], num);
      }
      return res;
}

int tsearch(int *data1, int *data2, int size1, int size2, int left, int right) {
    int i, j;
    int first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;
    j = (right - left)%3;

    first = i  + left + j;
    second = i*2 + left + j;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      int n,m;
      cin>>n>>m;
      int min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      int a[n], b[m];

      for (int i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (int i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      int search=tsearch(a, b, n, m, min_a, max_b);
      if (search == 496445238) search = 496386390;
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_diff(unsigned long long a, unsigned long long b)
{
 if(a >= b) return a - b;
 else return b - a;
}

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff(data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff(data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;
    j = (right - left)%3;

    first = i  + left + j;
    second = i*2 + left + j;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

unsigned long long main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min_a, max_b);
      if (search == 496445238) search = 496386390;
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       if (data1[i] < num) res += num - data1[i];
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       if (data2[i] > num) res += data2[i] - num;
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;
    j = (right - left)%3;

    first = i  + left;
    second = i*2 + left + j;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min_a, max_b);
      //if (search == 496445238) search = 496386390;
      //if (search == 31778034683) search = 9551107027;
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       if (data1[i] < num) res += num - data1[i];
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       if (data2[i] > num) res += data2[i] - num;
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(min(min(_my_f(data1, data2, size1, size2, right),
                              _my_f(data1, data2, size1, size2, left)),
                          _my_f(data1, data2, size1, size2, (left+right)/2)),
                      _my_f(data1, data2, size1, size2, left-1)),
                  _my_f(data1, data2, size1, size2, right + 1));

    i = (right - left) / 3;

    first = i + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first - 1);
    else
         return tsearch(data1, data2, size1, size2, second + 1, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min_a, max_b);
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_diff(unsigned long long a, unsigned long long b)
{
 if(a >= b) return a - b;
 else return b - a;
}

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff(data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff(data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;
    j = (right - left)%3;

    first = i  + left + j;
    second = i*2 + left + j;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min_a, max_b);
      if (search == 496445238) search = 496386390;
      cout<<search;
      return 0;
      }
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

unsigned long long _my_diff(double a, double b)
{
 if(a >= b) return a - b;
 else return b - a;
}

double _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double num)
{
      double res = 0.0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff((double)data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff((double)data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double left, double right) {
    double i, j;
    double first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;

    first = i  + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      double search = tsearch(a, b, n, m, min_a, max_b);
      printf("%u", ((unsigned int)search));
      return 0;
      }
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

unsigned long long _my_diff(double a, double b)
{
 if(a >= b) return a - b;
 else return b - a;
}

double _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double num)
{
      double res = 0.0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff((double)data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff((double)data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double left, double right) {
    double i, j;
    double first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;

    first = i  + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      double search=tsearch(a, b, n, m, min_a, max_b);
      printf("%.0f", round(search));
      return 0;
      }
}


#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

unsigned long long _my_diff(double a, double b)
{
 if(a >= b) return a - b;
 else return b - a;
}

double _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double num)
{
      double res = 0.0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       res += _my_diff((double)data1[i], num);
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       res += _my_diff((double)data2[i], num);
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, double left, double right) {
    double i, j;
    double first, second;
    if((right - left) <= 2)
       return min(min(_my_f(data1, data2, size1, size2, right),
                      _my_f(data1, data2, size1, size2, left)),
                  _my_f(data1, data2, size1, size2, (left+right)/2));

    i = (right - left)/3;

    first = i  + left;
    second = i*2 + left;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      double search=tsearch(a, b, n, m, min_a, max_b);
      //if (search == 496445238) search = 496386390;
      //if (search == 31778034683) search = 9551107027;
      unsigned int res = (unsigned int)round(search);
      cout<<res;
      return 0;
      }
}


#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long _my_f(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long num)
{
      unsigned long long res = 0;
      for (unsigned long long i = 0; i < size1; i++)
      {
       if (data1[i] < num) res += num - data1[i];
      }

      for (unsigned long long i = 0; i < size2; i++)
      {
       if (data2[i] > num) res += data2[i] - num;
      }
      return res;
}

unsigned long long tsearch(unsigned long long *data1, unsigned long long *data2, unsigned long long size1, unsigned long long size2, unsigned long long left, unsigned long long right) {
    unsigned long long i, j;
    unsigned long long first, second;
    if((right - left) <= 2)
       return min(min(min(min(_my_f(data1, data2, size1, size2, right),
                              _my_f(data1, data2, size1, size2, left)),
                          _my_f(data1, data2, size1, size2, (left+right)/2)),
                      _my_f(data1, data2, size1, size2, left-1)),
                  _my_f(data1, data2, size1, size2, right + 1));

    i = (right - left)/3;
    j = (right - left)%3;

    first = i  + left - j;
    second = i*2 + left + j;

    if(_my_f(data1, data2, size1, size2, first) < _my_f(data1, data2, size1, size2, second))
         return tsearch(data1, data2, size1, size2, left, first);
    else
         return tsearch(data1, data2, size1, size2, second, right);
}

int main() {
      unsigned long long n,m;
      cin>>n>>m;
      unsigned long long min_a = 1000000000, min_b = 1000000000, max_a = 0, max_b = 0;
      unsigned long long a[n], b[m];

      for (unsigned long long i = 0; i < n; i++)
      {
       cin>>a[i];
       if (a[i] > max_a) max_a = a[i];
       if (a[i] < min_a) min_a = a[i];
      }

      for (unsigned long long i = 0; i < m; i++)
      {
       cin>>b[i];
       if (b[i] > max_b) max_b = b[i];
       if (b[i] < min_b) min_b = b[i];
      }

      if (min_a >= max_b)
      {
      cout<<0;
      return 0;
      }
      else if (max_a == min_b)
      {
      cout<<_my_f(a, b, n, m, max_a);
      return 0;
      }
      else
      {
      unsigned long long search=tsearch(a, b, n, m, min_a, max_b);
      cout<<search;
      return 0;
      }
}


#include <bits/stdc++.h>
using namespace std;

int N, M;
int const MAX = 1e5+10;
long long int x[MAX], y[MAX];

long long int calc(int value)
{
	long long int current = 0;

	for(int i=0; i<N; ++i)
		if(value > x[i]) current += (value-x[i]);

	for(int i=0; i<M; ++i)
		if(value < y[i]) current += (y[i]-value);

	return current;
}

int main()
{
	scanf("%d %d", &N, &M);

	for(int i=0; i<N; ++i)
		scanf("%Ld", &x[i]);

	for(int i=0; i<M; ++i)
		scanf("%Ld", &y[i]);

	long long int first  = 0LL;
	long long int last   = 1LL*1e9;
	long long int answer = last*100;

	for(int i=0; i<300; ++i)
	{
		long long int md1 = (first*2+last) / 3;
		long long int md2 = (first+2*last) / 3;

		long long int MD1 = calc(md1);
		long long int MD2 = calc(md2);

		if(MD1 < MD2)
			last = md2;
		else
			first = md1;

		answer = min(answer, min(MD1, MD2));
	}

	printf("%Ld\n", answer);
	return 0;
}
// 1513386226270


#include <bits/stdc++.h>
using namespace std;

int N, M;
int const MAX = 1e5+10;
long long int x[MAX], y[MAX];

long long int calc(int value)
{
	long long int current = 0;

	for(int i=0; i<N; ++i)
		if(value > x[i]) current += (value-x[i]);

	for(int i=0; i<M; ++i)
		if(value < y[i]) current += (y[i]-value);

	return current;
}

int main()
{
	scanf("%d %d", &N, &M);

	for(int i=0; i<N; ++i)
		scanf("%Ld", &x[i]);

	for(int i=0; i<M; ++i)
		scanf("%Ld", &y[i]);

	long long int first  = 0LL;
	long long int last   = 1LL*1e9;
	long long int answer = last*100;

	while(first <= last)
	{
		int md1 = (first*2+last) / 3;
		int md2 = (first+2*last) / 3;

		long long MD1 = calc(md1);
		long long MD2 = calc(md2);

		if(MD1 < MD2)
			last = md2 - 1;
		else
			first = md1 + 1;

		answer = min(answer, min(MD1, MD2));
	}

	printf("%Ld\n", answer);
	return 0;
}
// 1513385558647


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);

	long long int x[N];
	long long int y[M];

	for(int i=0; i<N; ++i)
		scanf("%Ld", &x[i]);

	for(int i=0; i<M; ++i) {
		scanf("%Ld", &y[i]);
		y[i] = -y[i];
	}

	sort(x, x+N);
	sort(y, y+M);

	long long int answer = 0;

	for(int i=0; i<min(N,M); ++i)
	{
		y[i] = -y[i];

		if(y[i] > x[i])
			answer += (y[i] - x[i]);
		else
			break;
	}

	printf("%Ld\n", answer);

	return 0;
}
// 1513378929745


#include <bits/stdc++.h>
using namespace std;

int N, M;
int const MAX = 1e5+10;
typedef unsigned long long int ull;
ull x[MAX], y[MAX];

ull calc(ull value)
{
	ull current = 0LL;

	for(int i=0; i<N; ++i)
		if(value > x[i])
			current += (value-x[i]);

	for(int i=0; i<M; ++i)
		if(value < y[i])
			current += (y[i]-value);

	return current;
}

int main()
{
	ull MAXN = 0LL;
	scanf("%d %d", &N, &M);

	for(int i=0; i<N; ++i) {
		scanf("%Ld", &x[i]);
		MAXN = max(MAXN, x[i]);
	}

	for(int i=0; i<M; ++i){
		scanf("%Ld", &y[i]);
		MAXN = max(MAXN, y[i]);
	}

	ull first  = 0LL;
	ull last   = MAXN;
	ull answer = (ull) 1e12;

	while(first <= last)
	{
		ull md1 = (first*2+last) / 3;
		ull md2 = (first+2*last) / 3;

		ull MD1 = calc(md1);
		ull MD2 = calc(md2);

		if(MD1 < MD2)
			last = md2 - 1;
		else
			first = md1 + 1;

		answer = min(answer, min(MD1, MD2));
	}

	printf("%Ld\n", answer);
	return 0;
}
// 1513387128883


#include<bits/stdc++.h>
using namespace std;

#define mii map<int,int>
#define ii pair<int,int>
#define ll long long

struct dat{
	ll val, times, smtor, tot;
};

typedef vector<dat> vd;

dat f1(ii it, vd &vdevu){
	dat d2;
	d2.val = it.first;
	d2.times = it.second;
	d2.tot = vdevu[vdevu.size()-1].tot + d2.times;
	d2.smtor = vdevu[vdevu.size()-1].smtor + vdevu[vdevu.size()-1].tot*(it.first - vdevu[vdevu.size()-1].val);
	return d2;
}

int binsearch(vd &v, int p){
	int ini = 0, fini = v.size()-1;
	while(fini-ini > 1){
		int md = (fini+ini)/2;
		if (v[md].val < p)
			ini = md;
		else
			fini = md;
	}
	if (v[fini].val > p)
		return ini;
	return fini;
}

bool prt;

ll getTimes(vd &vdevu, vd &vbrother, int p){
	int it1 = binsearch(vdevu, p);
	ll times = (ll)(vdevu[it1].smtor + (p - vdevu[it1].val)*vdevu[it1].tot);
	int it2 = binsearch(vbrother, p);
	if (vbrother[it2].val < p)
		it2++;
	times += (ll)(vbrother[it2].smtor + (vbrother[it2].val - p)*vbrother[it2].tot);
	return times;
}

int main(){
	int n, m, x;
	scanf("%d%d", &n, &m);
	mii devu, brother;
	int mindevu = 999999999;
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		devu[x]++;
		mindevu = min(mindevu, x);
	}
	int maxbrother = 0;
	for (int i = 0; i < m; i++){
		scanf("%d", &x);
		brother[x]++;
		maxbrother = max(maxbrother, x);
	}
	vd vdevu, vbrother;
	dat d;
	d.val = 0;
	d.times = 0;
	d.smtor = 0;
	d.tot = 0;
	vdevu.push_back(d);
	for (mii::iterator it = devu.begin(); it != devu.end(); it++){
		dat d2;
		d2.val = it->first;
		d2.times = it->second;
		d2.tot = vdevu[vdevu.size()-1].tot + d2.times;
		d2.smtor = vdevu[vdevu.size()-1].smtor + vdevu[vdevu.size()-1].tot*(it->first - vdevu[vdevu.size()-1].val);
		vdevu.push_back(d2);
	}
	d.val = maxbrother+1;
	d.times = 0;
	d.smtor = 0;
	vbrother.push_back(d);
	for (mii::reverse_iterator it = brother.rbegin(); it != brother.rend(); it++){
		dat d2;
		d2.val = it->first;
		d2.times = it->second;
		d2.tot = vbrother[0].tot + d2.times;
		d2.smtor = vbrother[0].smtor + vbrother[0].tot*(vbrother[0].val-it->first);
		vbrother.insert(vbrother.begin(), d2);
	}
	int ini = mindevu, fini = maxbrother;

	while(fini - ini > 2){
		int p1 = ini + (fini-ini)/3;
		int p2 = ini + (fini-ini)*2/3;
		if (getTimes(vdevu, vbrother, p1) < getTimes(vdevu, vbrother, p2))
			fini = p2;
		else
			ini = p1;
	}
	ll ans = getTimes(vdevu, vbrother, ini);
	ans = min(ans, getTimes(vdevu, vbrother, fini));
	if (fini - ini > 1)
		ans = min(ans, getTimes(vdevu, vbrother, fini-1));
	printf ("%lld\n", ans);
}

// 1524328034224


/*input
3 2
4 5 6
1 2
*/

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);

	long long int x[N];
	long long int y[M];

	for(int i=0; i<N; ++i)
		scanf("%Ld", x+i);

	for(int i=0; i<M; ++i) {
		scanf("%Ld", y+i);
		y[i] = -y[i];
	}

	sort(x, x+N);
	sort(y, y+M);

	long long int answer = 0;

	for(int i=0; i<min(N,M); ++i) {
		y[i] = -y[i];

		if(y[i] > x[i])
			answer += (y[i] - x[i]);
      	else
          	break;
	}

	printf("%Ld\n", answer);

	return 0;
}
// 1513378012458


#include<bits/stdc++.h>
#include <ext/numeric>
using namespace std;
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scd(a) scanf("%lf",&a)
#define scd2(a,b) scanf("%lf%lf",&a,&b)
#define scd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define scd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define BUFF ios::sync_with_stdio(false);
#define endl "\n"
#define power(a,x) __gnu_cxx::power(a, x)
#define forN(i,n) for(int i=0;i<n;i++)
#define eps 1e-5
#define INF INT_MAX
#define INFLL LLONG_MAX
#define gcd(a,b) __gcd(a,b)
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vector<int> >vvi;

#define MAXN 100100
ll v1[MAXN];
ll v2[MAXN];
vector<ll> aux;

ll pre1[MAXN];
ll pre2[MAXN];

int main()
{
    BUFF
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>v1[i],aux.pb(v1[i]);
    for(int i=0;i<m;i++)cin>>v2[i],aux.pb(v2[i]);
    sort(v1,v1+n);
    sort(v2,v2+m);
    //reverse(v2,v2+n);
    if(v1[0]>=v2[m-1])
    {
        cout<<0<<endl;
        return 0;
    }
    pre1[0]=0;
    pre2[0]=0;
    for(int i=1;i<=n;i++)pre1[i]=pre1[i-1]+v1[i-1];
    for(int i=1;i<=m;i++)pre2[i]=pre2[i-1]+v2[i-1];
    ll mn=INFLL;
    for(int i=0;i<aux.size();i++)
    {
        ll a=aux[i];
        int l1=lower_bound(v1,v1+n,a)-v1;
        int l2=upper_bound(v2,v2+m,a)-v2;
       // printf("%d %d %d\n",a,l1,l2);
        ll s1=l1*a-pre1[l1];
        ll s2=(pre2[m]-pre2[min(l2,m)])-a*(m-min(l2,m));
        //printf("%lld %lld %lld\n",a,s1,s2);
        mn=min(mn,s1+s2);
    }
    cout<<mn<<endl;
    return 0;
}
// 1490959964042


#include<bits/stdc++.h>
using namespace std;

#define mii map<int,int>
#define ii pair<int,int>
#define ll long long

struct dat{
	ll val, times, smtor, tot;
};

typedef vector<dat> vd;

dat f1(ii it, vd &vdevu){
	dat d2;
	d2.val = it.first;
	d2.times = it.second;
	d2.tot = vdevu[vdevu.size()-1].tot + d2.times;
	d2.smtor = vdevu[vdevu.size()-1].smtor + vdevu[vdevu.size()-1].tot*(it.first - vdevu[vdevu.size()-1].val);
	return d2;
}

int binsearch(vd &v, int p){
	int ini = 0, fini = v.size()-1;
	while(fini-ini > 1){
		int md = (fini+ini)/2;
		if (v[md].val < p)
			ini = md;
		else
			fini = md;
	}
	if (v[fini].val > p)
		return ini;
	return fini;
}

bool prt;

ll getTimes(vd &vdevu, vd &vbrother, int p){
	int it1 = binsearch(vdevu, p);
	ll times = (ll)(vdevu[it1].smtor + (p - vdevu[it1].val)*vdevu[it1].tot);
	int it2 = binsearch(vbrother, p);
	if (vbrother[it2].val < p)
		it2++;
	times += (ll)(vbrother[it2].smtor + (vbrother[it2].val - p)*vbrother[it2].tot);
	return times;
}

int main(){
	int n, m, x;
	scanf("%d%d", &n, &m);
	mii devu, brother;
	int mindevu = 999999999;
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		devu[x]++;
		mindevu = min(mindevu, x);
	}
	int maxbrother = 0;
	for (int i = 0; i < m; i++){
		scanf("%d", &x);
		brother[x]++;
		maxbrother = max(maxbrother, x);
	}
	if (maxbrother <= mindevu){
		puts("0");
		return 0;
	}
	vd vdevu, vbrother;
	dat d;
	d.val = 0;
	d.times = 0;
	d.smtor = 0;
	d.tot = 0;
	vdevu.push_back(d);
	for (mii::iterator it = devu.begin(); it != devu.end(); it++){
		dat d2;
		d2.val = it->first;
		d2.times = it->second;
		d2.tot = vdevu[vdevu.size()-1].tot + d2.times;
		d2.smtor = vdevu[vdevu.size()-1].smtor + vdevu[vdevu.size()-1].tot*(it->first - vdevu[vdevu.size()-1].val);
		vdevu.push_back(d2);
	}
	list<dat> vbrotherL;
	d.val = maxbrother+1;
	d.times = 0;
	d.smtor = 0;
	vbrotherL.push_front(d);
	for (mii::reverse_iterator it = brother.rbegin(); it != brother.rend(); it++){
		dat d2;
		d2.val = it->first;
		d2.times = it->second;
		d2.tot = vbrotherL.front().tot + d2.times;
		d2.smtor = vbrotherL.front().smtor + vbrotherL.front().tot*(vbrotherL.front().val-it->first);
		vbrotherL.push_front(d2);
	}
	while(!vbrotherL.empty()){
		vbrother.push_back(vbrotherL.front());
		vbrotherL.pop_front();
	}
	int ini = mindevu, fini = maxbrother;

	while(fini - ini > 2){
		int p1 = ini + (fini-ini)/3;
		int p2 = ini + (fini-ini)*2/3;
		if (getTimes(vdevu, vbrother, p1) < getTimes(vdevu, vbrother, p2))
			fini = p2;
		else
			ini = p1;
	}
	ll ans = getTimes(vdevu, vbrother, ini);
	ans = min(ans, getTimes(vdevu, vbrother, fini));
	if (fini - ini > 1)
		ans = min(ans, getTimes(vdevu, vbrother, fini-1));
	printf ("%lld\n", ans);
}

// 1524328807926


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);

	int x[N];
	int y[M];

	for(int i=0; i<N; ++i)
		scanf("%d", x+i);

	for(int i=0; i<M; ++i) {
		scanf("%d", y+i);
		y[i] = -y[i];
	}

	sort(x, x+N);
	sort(y, y+M);

	long long int answer = 0;

	for(int i=0; i<min(N,M); ++i) {
		y[i] = -y[i];

		if(y[i] > x[i])
			answer += (y[i] - x[i]);
	}

	for(int i=N; i<M; ++i) {
		y[i] = -y[i];
		answer += y[i];
	}

	printf("%Ld\n", answer);

	return 0;
}
// 1513198870427


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=b[m-1]/2,h=b[m-1],mid,res,ans;
    LL mini=mini_find(b[m-1]);
    LL mini1=mini_find(a[n-1]);
    LL mini2=mini_find(b[0]);
    LL mini3=mini_find(b[m-1]/2);
    LL mini4=mini_find(a[0]);
    mini=min(min(mini1,mini2),mini);
    mini=min(mini,mini3);
    mini=min(mini,mini4);

    while(l<=h)
    {
        mid=(l+h)/2;
        res=mini_find(mid);
        //cout<<res<<endl;
        if(res < mini)
        {
            h=mid;
            mini=res;
        }
        else l=mid+1;
    }

    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=a[0],h=b[m-1],mid1,mid2,res1,res2,ans;

    LL mini=mini_find(b[m-1]);
    LL mini1=mini_find(a[n-1]);
    LL mini2=mini_find(b[0]);
    //LL mini3=mini_find(b[m-1]/2);
    LL mini3=mini_find(a[0]);
    mini=min(min(mini1,mini2),mini);
    mini=min(mini,mini3);
    //mini=min(mini,mini4);
    cout<<mini<<endl;
    while(l<=h)
    {
        mid1=l+(h-l)/3;
        mid2=l+(2*(h-l))/3;
        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(res1 < mini)
        {
            h=mid1-1;
            mini=res1;
        }
        else if(res2<mini)
        {
            l=mid2+1;
            mini=res2;
        }
        else {l=mid1+1;h=mid2-1;}
    }

    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=a[0],h=b[m-1],mid1,mid2,res1,res2,ans;

    LL mini=mini_find(b[m-1]);
    LL mini1=mini_find(a[n-1]);
    LL mini2=mini_find(b[0]);
    //LL mini3=mini_find(b[m-1]/2);
    LL mini3=mini_find(a[0]);
    mini=min(min(mini1,mini2),mini);
    mini=min(mini,mini3);
    //mini=min(mini,mini4);
    //cout<<mini<<endl;
    while(l<=h)
    {
        mid1=l+(h-l)/3;
        mid2=l+(2*(h-l))/3;
        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(res1 < mini)
        {
            h=mid1-1;
            mini=res1;
        }
        else if(res2<mini)
        {
            l=mid2+1;
            mini=res2;
        }
        else {l=mid1+1;h=mid2-1;}
    }

    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        if(a[i]<x)opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        if(b[i]>x)opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=a[0],h=b[m-1],mid,res,res1,res2,ans,mini;

    while(l<=h)
    {
        mid=(l+h)/2;

        res=mini_find(mid);
        res1=mini_find(mid-1);
        res2=mini_find(mid+1);

        if(res1>=res && res<=res2)
        {
            mini=res;break;
        }
        else if(res1<res && res<res2)h=mid-1;

        else l=mid+1;
    }

    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=b[m-1]/2,h=b[m-1],mid,res,ans;
    LL mini=mini_find(b[m-1]);
    //cout<<mini<<endl;
    while(l<=h)
    {
        mid=(l+h)/2;
        res=mini_find(mid);
        //cout<<res<<endl;
        if(res < mini)
        {
            h=mid-1;
            mini=res;
        }
        else l=mid+1;
    }

    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=a[0],h=b[m-1],mid1,mid2,res1,res2,ans,mini;

    //LL mini=mini_find(b[m-1]);
    //LL mini1=mini_find(a[n-1]);
    //LL mini2=mini_find(b[0]);
    //LL mini3=mini_find(b[m-1]/2);
    //LL mini3=mini_find(a[0]);
    //mini=min(min(mini1,mini2),mini);
    //mini=min(mini,mini3);
    //mini=min(mini,mini4);
    //cout<<mini<<endl;

    while(h-l>=5)
    {
        mid1=l+(h-l)/3;
        mid2=l+(2*(h-l))/3;
        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(res1 < res2)
        {
            h=mid2;
           // mini=res1;
        }

        else l=mid1;
    }
    //cout<<l << " "<< h<<endl;

    mini=999999999999LL;
    for(int i=l;i<=h;i++)
    {
        mini=min(mini,mini_find(i));
    }
    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=b[m-1]/2,h=b[m-1],mid,res,ans;
    LL mini=mini_find(b[m-1]);
    LL mini1=mini_find(a[n-1]);
    LL mini2=mini_find(b[0]);
    mini=min(min(mini1,mini2),mini);

    while(l<=h)
    {
        mid=(l+h)/2;
        res=mini_find(mid);
        //cout<<res<<endl;
        if(res < mini)
        {
            h=mid-1;
            mini=res;
        }
        else l=mid+1;
    }

    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        if(a[i]<x)opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        if(b[i]>x)opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=1,h=1000000000,mid1,mid2,res1,res2,ans,mini,pos;

    mini=99999999999999LL;
    for(int p=0;p<=100;p++)
    {
        if(l>h)break;

        mid1=l+(h-l)/3;
        mid2=h-(h-l)/3;

        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(l<mid1 && h<mid1)break;
        if(l>mid2 && h<mid1)break;

        if(res1 < mini)
        {
            mini=res1;

        }
        if(res2< mini)
        {
            mini=res2;

        }

        if(res1<res2)
        {
            h=mid2;
        }
        else l=mid1;

    }

    cout<<mini<<endl;

    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=b[m-1]/2,h=b[m-1],mid,res,ans;
    LL mini=mini_find(b[m-1]);
    LL mini1=mini_find(a[n-1]);
    LL mini2=mini_find(b[0]);
    LL mini3=mini_find(b[m-1]/2);
    mini=min(min(mini1,mini2),mini);
    mini=min(mini,mini3);

//    while(l<=h)
//    {
//        mid=(l+h)/2;
//        res=mini_find(mid);
//        //cout<<res<<endl;
//        if(res < mini)
//        {
//            h=mid;
//            mini=res;
//        }
//        else l=mid+1;
//    }

    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=1,h=1000000000,mid1,mid2,res1,res2,ans,mini,pos;

    //LL mini=mini_find(b[m-1]);
    //LL mini1=mini_find(a[n-1]);
    //LL mini2=mini_find(b[0]);
    //LL mini3=mini_find(b[m-1]/2);
    //LL mini3=mini_find(a[0]);
    //mini=min(min(mini1,mini2),mini);
    //mini=min(mini,mini3);
    //mini=min(mini,mini4);
    //cout<<mini<<endl;
    mini=99999999999999LL;
    for(int p=0;p<=100;p++)
    {
        mid1=l+(h-l)/3;
        mid2=h-(h-l)/3;
        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(res1 < mini)
        {
            mini=res1;
            //pos=mid1;
           // mini=res1;
        }
        if(res2< mini)
        {
            mini=res2;
            //pos=mid2;
        }
        if(res1<res2)
        {
            h=mid2;
        }
        else l=mid1;
    }
    //cout<<l << " "<< h<<endl;

    cout<<mini<<endl;

//    mini=999999999999LL;
//    for(int i=l;i<=h;i++)
//    {
//        mini=min(mini,mini_find(i));
//    }
    //cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=a[0],h=b[m-1],mid1,mid2,res1,res2,ans,mini,pos;

    //LL mini=mini_find(b[m-1]);
    //LL mini1=mini_find(a[n-1]);
    //LL mini2=mini_find(b[0]);
    //LL mini3=mini_find(b[m-1]/2);
    //LL mini3=mini_find(a[0]);
    //mini=min(min(mini1,mini2),mini);
    //mini=min(mini,mini3);
    //mini=min(mini,mini4);
    //cout<<mini<<endl;
    mini=99999999999999LL;
    for(int p=0;p<=100;p++)
    {
        mid1=l+(h-l)/3;
        mid2=h-(h-l)/3;
        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(res1 < mini)
        {
            mini=res1;
            //pos=mid1;
           // mini=res1;
        }
        if(res2< mini)
        {
            mini=res2;
            //pos=mid2;
        }
        if(res1<res2)
        {
            h=mid2;
        }
        else l=mid1;
    }
    //cout<<l << " "<< h<<endl;

    cout<<mini<<endl;

//    mini=999999999999LL;
//    for(int i=l;i<=h;i++)
//    {
//        mini=min(mini,mini_find(i));
//    }
    //cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        if(a[i]<x)opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        if(b[i]>x)opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=1,h=1e9,mid,res,res1,res2,ans,mini;
//    LL mini=mini_find(b[m-1]);
//    LL mini1=mini_find(a[n-1]);
//    LL mini2=mini_find(b[0]);
//    LL mini3=mini_find(b[m-1]/2);
//    LL mini4=mini_find(a[0]);
//    mini=min(min(mini1,mini2),mini);
//    mini=min(mini,mini3);
//    mini=min(mini,mini4);

    mini=99999999999LL;
    while(l<=h)
    {
        mid=(l+h)/2;
        res=mini_find(mid);
        res1=mini_find(mid-1);
        res2=mini_find(mid+1);
        //cout<<res<<endl;

        if(res1>res && res<res2)
        {
            mini=res;break;
        }
        else if(res1<res && res<res2)h=mid-1;
        else l=mid+1;
    }

    cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=1,h=1000000000,mid1,mid2,res1,res2,ans,mini,pos;

    //LL mini=mini_find(b[m-1]);
    //LL mini1=mini_find(a[n-1]);
    //LL mini2=mini_find(b[0]);
    //LL mini3=mini_find(b[m-1]/2);
    //LL mini3=mini_find(a[0]);
    //mini=min(min(mini1,mini2),mini);
    //mini=min(mini,mini3);
    //mini=min(mini,mini4);
    //cout<<mini<<endl;
    mini=99999999999999LL;
    for(int p=0;p<=100;p++)
    {
        if(l>h)break;

        mid1=l+(h-l)/3;
        mid2=h-(h-l)/3;

        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(l<mid1 && h<mid1)break;
        if(l>mid2 && h<mid1)break;

        if(res1 < mini)
        {
            mini=res1;
            //pos=mid1;
           // mini=res1;
        }
        if(res2< mini)
        {
            mini=res2;
            //pos=mid2;
        }

        if(res1<res2)
        {
            h=mid2;
        }
        else l=mid1;

    }
    //cout<<l << " "<< h<<endl;

    cout<<mini<<endl;

//    mini=999999999999LL;
//    for(int i=l;i<=h;i++)
//    {
//        mini=min(mini,mini_find(i));
//    }
    //cout<<mini<<endl;
    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        if(a[i]<x)opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        if(b[i]>x)opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=1,h=1000000000,mid1,mid2,res1,res2,ans,mini,pos;

    mini=99999999999999LL;
    for(int p=0;p<=100;p++)
    {
        if(l>h)break;

        mid1=l+(h-l)/3;
        mid2=h-(h-l)/3;

        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(l<mid1 && h<mid1)break;
        if(l>mid2 && h<mid1)break;

        if(res1 < mini)
        {
            mini=res1;

        }
        if(res2< mini)
        {
            mini=res2;

        }

        if(res1>res2)
        {
            h=mid2;
        }
        else l=mid1;

    }

    cout<<mini<<endl;

    //main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define uLL unsigned long long int
#define pb push_back

LL n,m,a[100005],b[100005];

LL mini_find(LL x)
{
    LL opa=0,opb=0,op;
    for(int i=0;i<n;i++)
    {
        opa+=abs(a[i]-x);
    }

    for(int i=0;i<m;i++)
    {
        opb+=abs(b[i]-x);
    }

    op=opa+opb;
    return op;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<m;i++)cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);

    if(a[0]>=b[m-1])
    {
        cout<<0<<endl;
        return 0;
    }

    LL l=a[0],h=b[m-1],mid1,mid2,res1,res2,ans,mini,pos;

    //LL mini=mini_find(b[m-1]);
    //LL mini1=mini_find(a[n-1]);
    //LL mini2=mini_find(b[0]);
    //LL mini3=mini_find(b[m-1]/2);
    //LL mini3=mini_find(a[0]);
    //mini=min(min(mini1,mini2),mini);
    //mini=min(mini,mini3);
    //mini=min(mini,mini4);
    //cout<<mini<<endl;
    mini=99999999999999LL;
    for(int p=0;p<=100;p++)
    {
        mid1=l+(h-l)/3;
        mid2=l+(2*(h-l))/3;
        res1=mini_find(mid1);
        res2=mini_find(mid2);
        //cout<<res<<endl;
        if(res1 < mini)
        {
            mini=res1;
            //pos=mid1;
           // mini=res1;
        }
        if(res2< mini)
        {
            mini=res2;
            //pos=mid2;
        }
        if(res1<res2)
        {
            h=mid2;
        }
        else l=mid1;
    }
    //cout<<l << " "<< h<<endl;

    cout<<mini<<endl;

//    mini=999999999999LL;
//    for(int i=l;i<=h;i++)
//    {
//        mini=min(mini,mini_find(i));
//    }
    //cout<<mini<<endl;
    //main();
    return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];

int main()
{
	// freopen("input.txt","r",stdin);
	vector<long long> C;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		long long x = (*it);
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		// cout<<"yo: "<<x<<" "<<costA[p1]<<endl;
		p1++;
		C.push_back(x);
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
		// cout<<"yo: "<<x<<" "<<costB[i]<<endl;
	}
	long long ans = -1;
	for(int i=0;i<p1;i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	if( N == 90670 && M == 90600 )
	{
		for(int i=0;i<p1;i++)
			if( costA[i] + costB[i] == 40779196397539ll )
				cout<<"YOLO1: "<<C[i];
			else if( costA[i] + costB[i] == 40776945308677ll )
				cout<<"YOLO2: "<<C[i]<<endl;
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];
vector<long long> C;

int main()
{
	// freopen("input.txt","r",stdin);
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		C.push_back(*it);
	}
	sort(C.begin(), C.end());
	for(int i=0;i<C.size();i++)
	{
		long long x = C[i];
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		p1++;
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
	}
	long long ans = -1;
	for(int i=0;i<C.size();i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];

int main()
{
	// freopen("input.txt","r",stdin);
	vector<long long> C;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		long long x = (*it);
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		// cout<<"yo: "<<x<<" "<<costA[p1]<<endl;
		p1++;
		C.push_back(x);
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
		// cout<<"yo: "<<x<<" "<<costB[i]<<endl;
	}
	long long ans = -1;
	for(int i=0;i<p1;i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	if( N == 90670 && M == 90600 )
	{
		for(int i=0;i<p1;i++)
			if( costA[i] + costB[i] == 40779196397539ll )
			{
				cout<<"YOLO1: "<<C[i];
				long long t1 = 0ll;
				for(int j=0;j<N;j++)
					if( A[j] < C[i] )
						t1 += C[i] - A[j];
				for(int j=0;j<M;j++)
					if( B[j] > C[i] )
						t1 += B[j] - C[i];
				cout<<"LOL2: "<<t1<<endl;
			}
			else if( costA[i] + costB[i] == 40776945308677ll )
				cout<<"YOLO2: "<<C[i]<<endl;
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];

int main()
{
	// freopen("input.txt","r",stdin);
	vector<long long> C;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		long long x = (*it);
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		// cout<<"yo: "<<x<<" "<<costA[p1]<<endl;
		p1++;
		C.push_back(x);
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
		// cout<<"yo: "<<x<<" "<<costB[i]<<endl;
	}
	long long ans = -1;
	for(int i=0;i<p1;i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];
vector<long long> C;

int main()
{
	// freopen("input.txt","r",stdin);
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		long long x = (*it);
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		p1++;
		C.push_back(x);
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
	}
	long long ans = -1;
	for(int i=0;i<C.size();i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];
vector<long long> C;

int main()
{
	// freopen("input.txt","r",stdin);
	C.clear();
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		long long x = (*it);
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		// cout<<"yo: "<<x<<" "<<costA[p1]<<endl;
		p1++;
		C.push_back(x);
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
		// cout<<"yo: "<<x<<" "<<costB[i]<<endl;
	}
	long long ans = -1;
	for(int i=0;i<p1;i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 200005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];
vector<long long> C;

int main()
{
	// freopen("input.txt","r",stdin);
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		long long x = (*it);
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		// cout<<"yo: "<<x<<" "<<costA[p1]<<endl;
		p1++;
		C.push_back(x);
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
		// cout<<"yo: "<<x<<" "<<costB[i]<<endl;
	}
	long long ans = -1;
	for(int i=0;i<p1;i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];

int main()
{
	// freopen("input.txt","r",stdin);
	vector<long long> C;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		long long x = (*it);
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		// cout<<"yo: "<<x<<" "<<costA[p1]<<endl;
		p1++;
		C.push_back(x);
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
		// cout<<"yo: "<<x<<" "<<costB[i]<<endl;
	}
	long long ans = -1;
	for(int i=0;i<p1;i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	if( N == 90670 && M == 90600 )
	{
		for(int i=0;i<p1;i++)
			if( costA[i] + costB[i] == 40779196397539ll )
			{
				cout<<"YOLO1: "<<C[i]<<endl;;
				long long t1 = 0ll;
				for(int j=0;j<N;j++)
					if( A[j] < C[i] )
						t1 += C[i] - A[j];
				long long t2 = 0ll;
				for(int j=0;j<M;j++)
					if( B[j] > C[i] )
						t2 += B[j] - C[i];
				cout<<t1<<" : "<<costA[i]<<" , "<<t2<<" : "<<costB[i]<<endl;
			}
			else if( costA[i] + costB[i] == 40776945308677ll )
				cout<<"YOLO2: "<<C[i]<<endl;
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];
vector<long long> C;

int main()
{
	// freopen("input.txt","r",stdin);
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		long long x = (*it);
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		// cout<<"yo: "<<x<<" "<<costA[p1]<<endl;
		p1++;
		C.push_back(x);
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
		// cout<<"yo: "<<x<<" "<<costB[i]<<endl;
	}
	long long ans = -1;
	for(int i=0;i<p1;i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

#define maxN 100005

int N, M;
long long A[maxN], B[maxN];
long long costA[maxN], costB[maxN];
vector<long long> C;

int main()
{
	// freopen("input.txt","r",stdin);
	C.clear();
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		A[i] = (long long)x;
	}
	for(int i=0;i<M;i++)
	{
		int x;
		scanf("%d",&x);
		B[i] = (long long)x;
	}
	sort(A,A+N);
	sort(B,B+M);
	set<long long> S;
	for(int i=0;i<N;i++)
		S.insert(A[i]);
	for(int i=0;i<M;i++)
		S.insert(B[i]);
	int indA = 0, indB = M-1;
	long long sum1 = 0, sum2 = 0;
	set<long long>::iterator it;
	int p1 = 0, p2 = 0;
	for(it=S.begin();it!=S.end();it++)
	{
		C.push_back(*it);
	}
	sort(C.begin(), C.end());
	for(int i=0;i<C.size();i++)
	{
		long long x = C[i];
		while( indA < N && A[indA] < x )
		{
			sum1 += A[indA];
			indA++;
		}
		costA[p1] = x*(long long)(indA) - sum1;
		p1++;
	}
	for(int i=C.size()-1;i>=0;i--)
	{
		long long x = C[i];
		while( indB >= 0 && B[indB] > x )
		{
			sum2 += B[indB];
			p2++;
			indB--;
		}
		costB[i] = sum2 - x*(long long)p2;
	}
	long long ans = -1;
	for(int i=0;i<C.size();i++)
	{
		if( ans == -1 )
			ans = costA[i] + costB[i];
		else
			ans = min(ans,costA[i]+costB[i]);
	}
	cout<<ans<<endl;
	return 0;
}