from operator import attrgetter
from bisect import insort
from bisect import bisect_right

class Person:
    height = 0
    head = 0
    female = False
    id = 0

    def __lt__(self,other):
        if self.head < other.head:
            return True
        if self.head > other.head:
            return False
        if self.height > other.height:
            return True
        if self.height < other.height:
            return False
        if self.id < other.id:
            return True
        return False

def main():
    n = int(input())
    people = []
    men = []
    for i in range(0,2*n):
        p = Person()
        p.height, p.head =  [int(x) for x in input().split()]
        p.id = i
        p.female = (i>=n)
        people.append(p)
    people.sort(key=attrgetter("head"), reverse=True)
    people.sort(key=attrgetter("height"), reverse=True)
    result = 0
    for p in people:
        if p.female:
            matching_man = bisect_right(men, p)
            if matching_man!=len(men):
                result += (men[matching_man].height - p.height) + (men[matching_man].head - p.head)
                del(men[matching_man])  # O(n) sadly
            else:
                print("NIE")
                return
        else:
            insort(men, p)  # O(n) sadly        
    print(result)
        
if __name__ == '__main__': 
    main()
