组合dp。
/*
* 离散成一些开区间;
* 用f[i,j]表示最后一个取到i这个学校,取值在第j段的方案数;
* 转移,考虑前一个取到的学校;
* 如果之前取的数小于j这个区间,则直接全部累加;
* 否则之前的数在这个区间内;
* 假设[l,r)中只有m所学校能满足派出数量在j区间中的划艇,设j区间的大小为l;
* 计算出cal(l,r,j)表示[l,r)中每所学校都在j区间中选数,可选可不选;
* 第r所学校必须选,序列递增的方案数;
* cal(l,r,j)=sigma(C(l,i)*C(m,i-1))(1<=i<=m+1)=C(l+m,m+1);
* 枚举每一段j,依次考虑,组合数可以预处理;
* 并使用前缀和优化;
* http://blog.csdn.net/ruoruo_cheng/article/details/51873577
*/
#include<bits/stdc++.h>
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)
#define N 505
#define ll long long
#define mod 1000000007
using namespace std;
int n, tot, a[N], b[N], num[N<<1], g[N], C[N], inv[N];
int main() {
scanf("%d", &n);
inv[1] = 1; rep(i, 2, n) inv[i] = (ll)(mod-mod/i)*inv[mod%i]%mod;
rep(i, 1, n) {
scanf("%d%d", &a[i], &b[i]);
num[++tot] = a[i]; num[++tot] = b[i]+1;
}
sort(num+1, num+1+tot); tot = unique(num+1, num+1+tot)-num-1;
rep(i, 1, n) {
a[i] = lower_bound(num+1, num+1+tot, a[i])-num;
b[i] = lower_bound(num+1, num+1+tot, b[i]+1)-num;
}
C[0] = 1; g[0] = 1;
rep(j, 1, tot-1) {
int len = num[j+1]-num[j];
rep(i, 1, n) C[i] = (ll)C[i-1]*(len+i-1)%mod*inv[i]%mod;
per(i, n, 1) if(a[i] <= j && j+1 <= b[i]) {
int f = 0, m = 1, c = len;//m是i-p
per(p, i-1, 0) {
f = (f+(ll)c*g[p]%mod)%mod;
if(a[p] <= j && j+1 <= b[p]) c = C[++m];
} g[i] = (g[i]+f)%mod;
}
}
int ans = 0; rep(i, 1, n) ans = (ans+g[i])%mod;
printf("%d\n", ans);
return 0;
}