// Original C++ solution (slower):
#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL) INF;



const int MAX = 3 * 1000 * 100+47;

const double EPS = 1e-8;

const int MOD = 1000 * 1000 * 1000 + 7;



pair<PII, int> A[MAX];

int B[MAX];

int L[MAX], R[MAX];

int T[MAX];





int main()

{

    int n;

    scanf("%d", &n);

    FOR(i, 0, n)

    {

        int x, y;

        scanf("%d%d", &A[i].first.first, &A[i].first.second);

    }

    sort(A, A + n);

    FOR(i, 0, n)A[i].second = i;

    FOR(i, 0, n)swap(A[i].first.first, A[i].first.second);

    sort(A, A+n);

    FOR(i, 0, n)B[A[i].second] = i;

    

    FOR(i, 0, n)R[i] = max(i ? R[i-1] : -INF, B[i]);

    RFOR(i, n, 0)L[i] = min(i == n - 1 ? INF : L[i+1], B[i]) ;

    FOR(i, 0, n)R[i]++, L[i]++;

    

    FOR(j, 0, n)

    {

        int res = 0;

        for(int i = R[j]; i; i -= i & (-i))

            (res += T[i]) %= MOD;

        for(int i = max(0, L[j]-2); i; i -= i & (-i))

            (res += MOD - T[i]) %= MOD;

        (res += (L[j] == 1)) %= MOD;

        for(int i = R[j]; i <= n; i += i & (-i))

            (T[i] += res) %= MOD;

    }

    

    

    int ans = 0;

    for(int i = n; i; i -= i & (-i)) (ans += T[i]) %= MOD;

    for(int i = n-1; i; i -= i & (-i)) (ans += MOD - T[i]) %= MOD;

    printf("%d\n", ans);

    

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;



const int MAXN=200005;

const int MOD=1e9+7;

const int INF=0x3f3f3f3f;



int n;

int L[MAXN],R[MAXN];

int dp[MAXN];

struct node

{

	int X,V,id;

	node(){};

	node(int _X,int _V):X(_X),V(_V){};

}nd[MAXN+5];



bool cmp1(const node &a,const node &b){return a.X<b.X;}

bool cmp2(const node &a,const node &b){return a.V<b.V;}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

		scanf("%d %d",&nd[i].X,&nd[i].V);

	sort(nd+1,nd+1+n,cmp2);

	for(int i=1;i<=n;i++)

		nd[i].id=i;

	sort(nd+1,nd+1+n,cmp1);

	int mx=-1,mn=INF;

	for(int i=1;i<=n;i++){

		mx=max(mx,nd[i].id);

		R[i]=mx;

	}

	for(int i=n;i>=1;i--){

		mn=min(mn,nd[i].id);

		L[i]=mn;

	}

	int pos=0,sum=1;

	dp[0]=1;

	for(int i=1;i<=n;i++){

		while(R[pos]<L[i]-1)

			sum=((1ll*sum-1ll*dp[pos])%MOD+MOD)%MOD,pos++;

		dp[i]=sum;

		sum=(1ll*dp[i]+1ll*sum)%MOD;

	}

	int ans=0;

	for(int i=1;i<=n;i++)

		if(R[i]>=n)

			ans=(1ll*ans+1ll*dp[i])%MOD;

	printf("%d\n",ans);

}


// Fastest known solution for this problem: