x = int(raw_input()) y = int(raw_input()) l = int(raw_input()) c = (x + l - 1) % l + (y + l - 1) % l if y < 0: c += 2 elif x != 0: c += 1 print c