ans = 2000 n = int(input()) A = [] for _ in range(n): a, b = map(int, input().split()) A.append((a, b, b - a)) def f(num, l, max_A): global ans if max_A >= ans: return if l == 0: ans = max_A return for i in range(n): if (1 << i) & l: max_A = max(max_A, A[num][2] + A[i][0]) f(i, l - (1 << i), max_A) for i in range(n): f(i, ((1 << n) - 1) - (1 << i), 0) print(ans)