# 2個の整数A, Bが与えられる(B != 0) # AをBで割った余りを求めよ # # -100 <= A, B <= 100 # B != 0 import sys import itertools import time from math import radians, sin, cos, tan, sqrt from collections import deque def input(): return sys.stdin.readline().replace('\n','') sys.setrecursionlimit(1000000) md1 = 998244353 md2 = 10 ** 9 + 7 A, B = map(int, input().split()) r = A % B if r < 0: while not (0 <= r and r < abs(B)): r += abs(B) else: if 0 <= r and abs(B) <= r: while not(0 <= r and r < abs(B)): r -= abs(B) print(r)