local ffi = require 'ffi' local C = ffi.C ffi.cdef [[ int printf(const char *, ...); int scanf(const char *, ...); ]] C.printf("%d\n", (function (ct, m, n) 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)(ffi.typeof("long[1]"), 1000000007LL, tonumber(io.stdin:read("*l"))))