import sys
input = sys.stdin.readline
N = int(input())
lst = [list(map(int, input().split())) for _ in range(N)]
_MAX = 365
dp = [0] * (_MAX+2)
for s, e in lst:
for i in range(s, e+1):
dp[i] += 1
ans = 0
h, w = 0, 0
for v in dp:
if v == 0:
ans += h * w
h = w = 0
else:
h = max(h, v)
w += 1
print(ans)