Problem:
Score : 100 points

Problem Statement

Takahashi is distributing N balls to K persons.

If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?

Constraints

1 \leq K \leq N \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the maximum possible difference in the number of balls received.

Sample Input 1

3 2

Sample Output 1

1

The only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.

Thus, the maximum possible difference in the number of balls received is 1.

Sample Input 2

3 1

Sample Output 2

0

We have no choice but to give three balls to the only person, in which case the difference in the number of balls received is 0.

Sample Input 3

8 5

Sample Output 3

3

For example, if we give 1, 4, 1, 1, 1 balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be 3, which is the maximum result.

Solution in Fortran (gfortran v4.8.4) (judge verdict: Runtime Error)

integer N
integer,allocatable,dimension(:)::X
integer(8),allocatable,dimension(:)::ansx,ansy
integer(8)minuscnt,tmp
read*,N
allocate(X(N))
allocate(ansx(N-1),ansy(N-1))
read*,X
call heapsort(N,X)

minuscnt=0
do i=1,N
  if(x(i)<0)minuscnt=minuscnt+1
end do

if(minuscnt>=1.and. N-minuscnt>=1)then
  ansx(1)=X(1)
  ansy(1)=X(N-1)
  do i=2,(N-minuscnt)-2
    ansx(i)=ansx(i-1)-ansy(i-1)
    ansy(i)=ansy(minuscnt+i)
  end do
    ansy(N-minuscnt-1)=ansx(N-minuscnt-2)-ansy(N-minuscnt-2)
    ansx(N-minuscnt-1)=X(N)
  do i=N-minuscnt,N-1
    ansx(i)=ansx(i-1)+ansy(i-1)
    ansy(i)=ansy(N+1-i+1)
  end do
else
  ansx(1)=X(1)
  ansy(1)=X(N-1)
  do i=2,N-2
    ansx(i)=ansx(i-1)-ansy(i-1)
    ansy(i)=X(i)
  end do
  ansx(N-1)=X(N)
  ansy(N-1)=ansx(N-2)-ansy(N-2)
end if

ans=ansx(N-1)-ansy(N-1)
if(ans<0)then
  tmp=ansx(N-1)
  ansx(N-1)=ansy(N-1)
  ansy(N-1)=tmp
  ans=-ans
endif

print"(i0)",ansx(N-1)-ansy(N-1)
do i=1,N-1
  print"(i0,A,i0)",ansx(i)," ",ansy(i)
end do
contains

subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end