require'prime' m,n,*c=$<.read.split.map &:to_i d=[-1]*m<=0&&j<=i}}).map{|i|r+=i.prime?&&d[i]>0?d[i]:0} p r+d.max