print((function (f) return tostring(f(1000000007LL,io.stdin:read("*n"))):sub(1,-3) end)(function (m, n) local ffi = require'ffi' local C,ct = ffi.C,ffi.typeof("long[1]") ffi.cdef 'int scanf(const char *, ...);' local r,c,d = 0LL,ct(),ct() for _=1,n do C.scanf("%ld%ld",c,d) r=r+(((c[0]/2LL+(c[0]%2LL~=0LL and 1LL or 0LL))%m)*(d[0]%m))%m end return r%m end))