import sequtils, strutils let a, b, cd = stdin.readLine.split.map parseInt aw = a[0] ab = a[1] bw = b[0] c = cd[0] d = cd[1] var x = 0 y: int if c > ab: x = c - ab y = min(d, bw + x) echo aw - x + y