$routes=[]
$distance=[]
$condition=[]
@now=0
def get_fatigue (m,n,now_place)
  @now+=1
  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
n.times do |i| get_fatigue(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 && $routes[x][y]>$routes[x][y-1]
        $routes[x][y]=$routes[x][y-1]
    else
    end
  end
end
p $routes[n-1].min

