1060_D. Social Circles
You invited n guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles. 

Your guests happen to be a little bit shy, so the i-th guest wants to have a least l_i free chairs to the left of his chair, and at least r_i free chairs to the right. The "left" and "right" directions are chosen assuming all guests are going to be seated towards the center of the circle. Note that when a guest is the only one in his circle, the l_i chairs to his left and r_i chairs to his right may overlap.

What is smallest total number of chairs you have to use?

Input

First line contains one integer n — number of guests, (1 ⩽ n ⩽ 10^5). 

Next n lines contain n pairs of space-separated integers l_i and r_i (0 ⩽ l_i, r_i ⩽ 10^9).

Output

Output a single integer — the smallest number of chairs you have to use.

Examples

Input

3
1 1
1 1
1 1


Output

6


Input

4
1 2
2 1
3 5
5 3


Output

15


Input

1
5 6


Output

7

Note

In the second sample the only optimal answer is to use two circles: a circle with 5 chairs accomodating guests 1 and 2, and another one with 10 chairs accomodationg guests 3 and 4.

In the third sample, you have only one circle with one person. The guest should have at least five free chairs to his left, and at least six free chairs to his right to the next person, which is in this case the guest herself. So, overall number of chairs should be at least 6+1=7.
```python
import heapq
n=int(input())
fa=[i for i in range(n)]
ls=[]
rs=[]
for i in range(n):
    l,r=[int(x) for x in input().split()]
    ls.append((l,i))
    rs.append((r,i))
ls.sort()
rs.sort()
ans=n
for i in range(n):
    ans+=max(ls[i][0],rs[i][0])
# heapq.heapify(ls)
# heapq.heapify(rs)
#
# ans=n
# if n==1:
#     print(max(ls[0][0],rs[0][0])+1)
#     quit()
# for i in range(n):
#     ll=heapq.heappop(ls)
#     if fa[rs[0][1]]!=fa[ll[1]]:
#         rr=heapq.heappop(rs)
#         fa[ll[1]]=rr[1]
#     else:
#         tem=heapq.heappop(rs)
#         rr=heapq.heappop(rs)
#         fa[ll[1]]=rr[1]
#         heapq.heappush(rs,tem)
#     ans+=max(ll[0],rr[0])
print(ans)
```