local n = io.read("*n") local p, q = 1, 1 for i = 2, n do local a, b = io.read("*n", "*n") p, q = p + a, q + b end print(math.min(p, q))