gets
a,b=[x=0,*gets.bytes.map{$/=' '
x+=gets.to_i.*_1%7-4}].minmax
p b-a