a = [int(x) for x in input().split(',')] b = [int(x) for x in input().split(',')] c = int(input()) t = list(zip(a, b)) t.sort() for i in range(len(t)): if t[i][0] > c: break if t[i][0] >= t[i][1]: continue c += t[i][1] - t[i][0] print(c)