We have a single lecture hall available. Each lecturer submits an order specifying the time their lecture starts and the time it ends. We want to use the hall as much as possible. We accept some orders and reject others, aiming to maximize the total length of the lectures held in the hall. We assume that the moment one lecture ends, another may begin right away (each lecture occupies the hall only during an open time interval).
Write a program that:
The first line contains one positive integer n (n≤10000), the number of orders.
Each of the next n lines contains two integers p and k separated by a single space (0≤p<k≤30000). Such a pair represents one order: the lecture starts at time p and ends at time k (the lecturer uses the hall during the open interval (p,k)).
Print a single line containing the maximum possible total lecture time.