import sys m = 10**9+7 n = int(input()) l = [list(map(int, s.split())) for s in sys.stdin] l = sorted((x-t, t) for t, x in l) c = [1]+[0]*n d = 1 for i, (x, t) in enumerate(l): d += t for j in range(d-1, -1, -1): c[j] = (c[j-1]*j - c[j]*(x-i+j) if t else c[j]*(x-i+j)) % m print(sum(c)%m)