n, m = gets.split.map(&:to_i)
d = []
h = []
n.times{ d << gets.to_i }
m.times{ h << gets.to_i }
dp = Array.new(2){ Array.new(m, 1<<31) }
table = Array.new(n){ Array.new(m) }
n.times do |i|
  m.times do |j|
    table[i][j] = d[i] * h[j]
  end
end
m.times{ |i| dp[0][i] = table[0][i] }
(0...n-1).each do |j|
  (j+1..m-n+j+1).each do |k|
    (k+1..m-n+j+1).each do |i|
      dp[j%2^1][i] = [dp[j%2^1][i], dp[j%2][k] + table[j+1][i]].min
    end
  end
  dp[j%2].fill(1<<31)
end
p dp[n%2^1][n-1..-1].min