program gridian_mst
  implicit none
  integer :: w, h, i, a, b
  integer(8) :: c(200000,2), m
  c = 0_8
  read(*,*) w, h
  do i = 1, w
    read(*,*) c(i,1)
    c(i,2) = -1_8
  end do
  do i = w+1, w+h
    read(*,*) c(i,1)
    c(i,2) = 1_8
  end do
  call quick_sort(c(1:w+h,1:2),1)
  a = w+1
  b = h+1
  m = 0_8
  do i = 1, w+h
    if (c(i,2).lt.0_8) then
      if (a.eq.0) cycle
      m = m+c(i,1)*int(b,8)
      a = a-1
    else
      if (b.eq.0) cycle
      m = m+c(i,1)*int(a,8)
      b = b-1
    end if
  end do
  write(*,'(i0)') m
  stop
contains
  recursive subroutine quick_sort(a,i)
    implicit none
    integer(8), intent(inout) :: a(:,:)
    integer, intent(in) :: i
    integer(8) p, c(size(a(1,:)))
    integer :: n, l, r
    n = size(a(:,1))
    l = 1
    r = n
    p = a((l+r)/2,i)+a(l,i)+a(r,i)-max(a((l+r)/2,i),a(l,i),a(r,i))-min(a((l+r)/2,i),a(l,i),a(r,i))
    do
      do while (a(l,i).lt.p)
        l = l+1
      end do
      do while (a(r,i).gt.p)
        r = r-1
      end do
      if (l.ge.r) exit
      c = a(l,:)
      a(l,:) = a(r,:)
      a(r,:) = c
      l = l+1
      r = r-1
    end do
    if (l.gt.2) call quick_sort(a(1:l-1,:),i)
    if (n.gt.r+1) call quick_sort(a(r+1:n,:),i)
    return
  end subroutine quick_sort
end program gridian_mst