a = list(map(int, input().split())) l = len(a)-1 s = 0 for i in range(l): if a[0] > a[i+1]: s += a[i+1] print(s)