# A0611
# Silk Road
# @kankichi573
s = STDIN.gets.split
$n = s[0].to_i
$m  = s[1].to_i
$d = Array.new($n)
$c = Array.new($m)
$table = Array.new($n+1){Array.new($m+1,-1)}

0.upto($n-1){|i|
  $d[i] = STDIN.gets.split[0].to_i}
0.upto($m-1){|i|
  $c[i] = STDIN.gets.split[0].to_i
}

def solve(pos,dat)
  if $table[pos][dat] != -1
    $table[pos][dat]
  elsif(pos==$n)
    0
  elsif(dat==$m)
    ret = 9999999
  else
    # printf("%d %d\n",pos,dat)
    # printf("%d\n",$d[pos])
    # printf("%d\n",$c[dat])
    ret1 = $d[pos]*$c[dat] + solve(pos+1,dat+1) 
    ret2 = solve(pos,dat+1)
    
    ret=$table[pos][dat]=if ret1 > ret2
                          ret2
                        else
                          ret1
                        end
    ret
  end
end
puts solve(0,0)