import math

line = input()
words = line.split()
num_list = []
for word in words:
    num_list.append(int(word))
ans = 0
temp = 0

for i, num in enumerate(num_list):
    if i+1 < len(num_list) -1:
        break
    temp = math.gcd(num, num_list[i + 1])


for num in num_list:
    ans += (temp-1) % num

print(ans)