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