#-*- coding: utf-8
#  -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(n, k):
    if n % k == 0:
        return 0
    else:
        md = n % k
        dv = n / k
        return md



do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return n, k


if not do_submit:
    n, k = input_parse("""
    3 2
    """)
    print(sol(n, k))

    n, k = input_parse("""
    3 1
    """)
    print(sol(n, k))
    n, k = input_parse("""
    8 5
    """)
    print(sol(n, k))

else:
    n, k= list(map(int, input().split()))
    # S = input().split()
    # print(sol(n, k, S))
    #n = int(input().strip())
    # S = input().strip()
    print(sol(n, k))
 """
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
""" from collections import defaultdict import sys sys import math math from datetime import datetime def sol(n, k):
    if n % k == 0:
        return 0
    else:
        md = n % k
        dv = n / k
        return md sol if n % k == 0:
        return 0
    else:
        md = n % k
        dv = n / k
        return md n % k == 0 n % k n k 0 return 0 0 md = n % k md n % k n k dv = n / k dv n / k n k return md md n n k k do_submit = True do_submit True def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return n, k input_parse x.strip() for x in input_str.split("\n") if x.strip() for x in input_str.split("\n") if x.strip() x input_str.split("\n") input_str.split input_str split "\n" x.strip() x.strip x strip if x.strip() x.strip() x.strip x strip lines = [x.strip() for x in input_str.split("\n") if x.strip()] lines [x.strip() for x in input_str.split("\n") if x.strip()] list(map(str, line.split())) for line in lines for line in lines line lines for line in lines list(map(str, line.split())) list map(str, line.split()) map str line.split() line.split line split parsed_lines = [list(map(str, line.split())) for line in lines] parsed_lines [list(map(str, line.split())) for line in lines] print(parsed_lines) print parsed_lines n = int(parsed_lines[0][0]) n int(parsed_lines[0][0]) int parsed_lines[0][0] [0] parsed_lines 0 0 k = int(parsed_lines[0][1]) k int(parsed_lines[0][1]) int parsed_lines[0][1] [0] parsed_lines 0 1 return n, k return n, k n k input_str input_str if not do_submit:
    n, k = input_parse("""
    3 2
    """)
    print(sol(n, k))

    n, k = input_parse("""
    3 1
    """)
    print(sol(n, k))
    n, k = input_parse("""
    8 5
    """)
    print(sol(n, k))

else:
    n, k= list(map(int, input().split()))
    # S = input().split()
    # print(sol(n, k, S))
    #n = int(input().strip())
    # S = input().strip()
    print(sol(n, k)) not do_submit do_submit n, k = input_parse("""
    3 2
    """) n input_parse("""
    3 2
    """) input_parse """
    3 2
    """ k print(sol(n, k)) print sol(n, k) sol n k n, k = input_parse("""
    3 1
    """) n input_parse("""
    3 1
    """) input_parse """
    3 1
    """ k print(sol(n, k)) print sol(n, k) sol n k n, k = input_parse("""
    8 5
    """) n input_parse("""
    8 5
    """) input_parse """
    8 5
    """ k print(sol(n, k)) print sol(n, k) sol n k n, k= list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k print(sol(n, k)) print sol(n, k) sol n k k = input_parse("""
    3 2
    """) input_parse("""
    3 2
    """) k n, k= list(map(int, input().split())) list(map(int, input().split())) n n, k = input_parse("""
    3 1
    """) input_parse("""
    3 1
    """) n do_submit = True True do_submit k = input_parse("""
    8 5
    """) input_parse("""
    8 5
    """) k k= list(map(int, input().split())) list(map(int, input().split())) k def sol(n, k):
    if n % k == 0:
        return 0
    else:
        md = n % k
        dv = n / k
        return md def sol(n, k):
    if n % k == 0:
        return 0
    else:
        md = n % k
        dv = n / k
        return md sol def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return n, k def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return n, k input_parse k = input_parse("""
    3 1
    """) input_parse("""
    3 1
    """) k n, k = input_parse("""
    8 5
    """) input_parse("""
    8 5
    """) n n, k = input_parse("""
    3 2
    """) input_parse("""
    3 2
    """) n
#-*- coding: utf-8
#  -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(n, k):
    if n % k == 0:
        return 0
    else:
        md = n % k
        dv = n / k
        return md



do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return n, k


if not do_submit:
    n, k = input_parse("""
    3 2
    """)
    print(sol(n, k))

    n, k = input_parse("""
    3 1
    """)
    print(sol(n, k))
    n, k = input_parse("""
    8 5
    """)
    print(sol(n, k))

else:
    n, k= list(map(int, input().split()))
    # S = input().split()
    # print(sol(n, k, S))
    #n = int(input().strip())
    # S = input().strip()
    print(sol(n, k))

