require"prime";eval"N,L= ~-"+gets.split*',';s=0;Prime.each(L/N){|v|s-=~L+v*N};p s