$routes=[]
$distance=[]
$condition=[]
def counter
  count = 0
  ->{
    count += 1
    return count
  }
end

def get_fatigue (now,m,n,now_place)
  inner=[]
  now.upto(m-n+now) do |i|
    inner.push($distance[now_place]*$condition[i-1])#疲労度
  end
  $routes.push(inner)
end

a=gets.split("\s")
n=a[0].to_i
m=a[1].to_i
n.times do $distance.push(gets.chomp.to_i) end
  m.times do $condition.push(gets.chomp.to_i) end

    c=counter
    n.times do |i|
      get_fatigue(c.call,m,n,i)
    end
    0.upto(m-n) do |y|
      0.upto(n-1) do |x|
        if x>0 && y>0  then
          if $routes[x-1][y]+$routes[x][y]>$routes[x][y-1] then
            $routes[x][y]=$routes[x][y-1]
          else
            $routes[x][y]+= $routes[x-1][y]
          end
        elsif x>0
          $routes[x][y]+=$routes[x-1][y]
        elsif y>0
          if $routes[x][y]>$routes[x][y-1]
            $routes[x][y]=$routes[x][y-1]
        else
        end
      end
    end
    p $routes[n-1].min

