N = int(input()) AB = [list(map(int, input().split())) for _ in range(N)] XAB = [[AB[i][1] / AB[i][0], AB[i][0], AB[i][1]] for i in range(len(AB))] XAB.sort(reverse=True) _, Ai, Bi = XAB[0] _, Aj, Bj = XAB[1] _, Ak, Bk = XAB[2] ans = 0 for j in range(2020): for k in range(2020): i = (N - (Aj * j + Ak * k)) // Ai if i >= 0: ans = max(ans, Bi * i + Bj * j + Bk * k) print(ans)