### BUGGY CODE ###

from bisect import bisect, bisect_left
import fileinput

# def file_iterator(file_name):
#     with open(file_name) as f:
#         for line in f:
#             yield line

iterator = fileinput.input()
# iterator = file_iterator('input2.txt')



MAX_VELOCITY = 1000000000
MAX_N = 200000
MODULO =  1000000007


class Takahashi(object):
    def __init__(self, position, velocity):
        self.position = position
        self.velocity = velocity
        self.block_start = None
        self.block_end = None

    def set_block(self, start, end):
        self.block_start = start
        self.block_end = end

    def __repr__(self):
        return str({
            'position': self.position,
            'velocity': self.velocity,
            'block_start': self.block_start,
            'block_end': self.block_end
        })


class FirstNumberFinder(object):
    """Given a number in a sequence, it finds the first larger
    number from the start; or the first smaller number from the end."""
    def __init__(self, sequence, reversed_sequence=None, n=None):
        if not n:
            n = len(sequence)
        if not reversed_sequence:
            reversed_sequence = reversed(sequence)

        # find largest numbers
        b = []
        largest = -1
        for index, number in enumerate(sequence):
            if number > largest:
                b.append((number, index))
                largest = number
        b.sort()
        self.largest_numbers, self.largest_indices = zip(*b)
        # array for fast lookup
        self.largest = []
        for i, number in enumerate(self.largest_numbers):
            if i < len(self.largest_numbers) - 1:
                repeat_count = self.largest_indices[i + 1] - self.largest_indices[i]
            else:
                repeat_count = n - self.largest_indices[i]
            self.largest += [number] * repeat_count

        # find smallest numbers
        b = []
        smallest = 1000000001
        for index, number in enumerate(reversed_sequence):
            if number < smallest:
                b.append((number, n - index - 1))
                smallest = number
        b.sort()
        self.smallest_numbers, self.smallest_indices = zip(*b)
        # array for fast lookup
        self.smallest = []
        for i, number in enumerate(self.smallest_numbers):
            if i > 0:
                repeat_count = self.smallest_indices[i] - self.smallest_indices[i - 1]
            else:
                repeat_count = self.smallest_indices[0] + 1
            self.smallest += [number] * repeat_count

    def find_larger_from_start(self, number):
        """Returns tuple. First larger number and its index position in sequence from start."""
        index = bisect_left(self.largest_numbers, number)
        if index >= 0:
            return (self.largest_numbers[index], self.largest_indices[index])

    def find_smaller_from_end(self, number):
        """Returns tuple. First smaller number and its index position in sequence from end."""
        index = bisect(self.smallest_numbers, number) - 1
        if index >= 0:
            return (self.smallest_numbers[index], self.smallest_indices[index])


takahashis = []
blocks = []
block_starting_positions = dict()
block_ending_positions = dict()


# HANDLE INPUT
n = int(iterator.next())
for i in xrange(n):
    x, v = iterator.next().split()
    t = Takahashi(int(x), int(v))
    takahashis.append(t)


def turn_input_into_blocks():
    takahashis.sort(key=lambda takahashi: takahashi.position)
    number_finder = FirstNumberFinder(
        sequence=(t.velocity for t in takahashis),
        reversed_sequence=(t.velocity for t in reversed(takahashis)),
        n=n)
    for i, t in enumerate(takahashis):
        # find beginning of block
        if number_finder.largest[i] <= t.velocity:
            block_start = i
        else:
            larger_number, larger_number_index = number_finder.find_larger_from_start(t.velocity)
            block_start = larger_number_index

        # find end of block
        if number_finder.smallest[i]  >= t.velocity:
            block_end = i
        else:
            smaller_number, smaller_number_index = number_finder.find_smaller_from_end(t.velocity)
            block_end = smaller_number_index

        t.set_block(block_start, block_end)

        # add to block list if is current shortest
        saved_block_start_id = block_starting_positions.get(block_start)
        saved_block_end_id = block_ending_positions.get(block_end)
        test1 = (
            saved_block_start_id is None or
            block_end < takahashis[saved_block_start_id].block_end)
        test2 = (
            saved_block_end_id is None or
            block_start > takahashis[saved_block_end_id].block_start)

        if test1 and test2:
            block_starting_positions[block_start] = i
            block_ending_positions[block_end] = i
            if saved_block_start_id is not None:
                removed_block_end = takahashis[saved_block_start_id].block_end
                if block_ending_positions.get(removed_block_end) == saved_block_start_id:
                    del block_ending_positions[removed_block_end]
            if saved_block_end_id is not None:
                removed_block_start = takahashis[saved_block_end_id].block_start
                if block_starting_positions.get(removed_block_start) == saved_block_end_id:
                    del block_starting_positions[removed_block_start]


# possibilities[i] indicates the number of possibilities
# from block with indices 0 to i.
possibilities = [1] * (n + 1)



def compute_possibilities():
    # initialization hack, since index starts at 0
    possibilities[-1] = 1

    active_blocks = []

    for i in xrange(n):
        # update active blocks
        block_id = block_ending_positions.get(i - 1)
        if block_id is not None:
            active_blocks.remove(block_id)
        block_id = block_starting_positions.get(i)
        if block_id is not None:
            active_blocks.append(block_id)

        if not active_blocks:
            # This Takahashi can be set arbitrarily to Aoki or not
            result = 2 * possibilities[i - 1]

        else:
            # SET i to AOKI
            # Possibilities we have guaranteed
            result = possibilities[i - 1]

            # Other possibilities, we might get by zeroing blocks going into i
            for block_id in active_blocks:
                block_start = takahashis[block_id].block_start
                if block_start < i:
                    result += possibilities[block_start - 1]


            # SET i NOT to AOKI (or explore if possible)
            # Do all active blocks move more to left?
            all_blocks_move_to_left = True
            for block_id in active_blocks:
                block_start = takahashis[block_id].block_start
                if block_start >= i:
                    all_blocks_move_to_left = False
            if all_blocks_move_to_left:
                result += possibilities[i - 1]


        possibilities[i] = result % MODULO



turn_input_into_blocks()
# print block_starting_positions
# print block_ending_positions
compute_possibilities()
print possibilities[n-1]


### FIXED CODE ###

from bisect import bisect_left, bisect_right
import fileinput


MODULO = 1000000007
n = 0


# HANDLE INPUT
def handle_input():
    iterator = fileinput.input()
    global n
    n = int(next(iterator))
    takahashis = [None] * n
    for i in xrange(n):
        x, v = next(iterator).split()
        takahashis[i] = (int(x), int(v))
    return takahashis


def build_blocks(takahashis):
    result = [-1] * (n + 1)
    max_velocities = [0] * n
    min_velocities = [MODULO] * (n + 1)
    for i in xrange(n):
        max_velocities[i] = max(max_velocities[i - 1], takahashis[i][1])
    for i in xrange(n-1, -1, -1):
        min_velocities[i] = min(min_velocities[i + 1], takahashis[i][1])
    for i in xrange(n):
        current_velocity = takahashis[i][1]
        block_start = bisect_left(max_velocities, current_velocity)
        block_end = bisect_right(min_velocities, current_velocity) - 1
        result[block_end] = max(result[block_end], block_start)
    return result


def compute_possibilities(blocks):
    possibilities = [1] * (n + 2)
    zeros_end_cursor = -2
    for current_position in xrange(n):
        result = 2 * possibilities[current_position - 1]
        # Remove possibiltiies for (00..)1{.....} sequences.
        while zeros_end_cursor < blocks[current_position] - 1:
            result -= possibilities[zeros_end_cursor]
            zeros_end_cursor += 1
        possibilities[current_position] = result % MODULO
    return possibilities[n - 1]


def main():
    takahashis = handle_input()
    takahashis.sort()
    blocks = build_blocks(takahashis)
    return compute_possibilities(blocks)


if __name__ == '__main__':
    print main()