#include <stdio.h>

int main(int argc, char *argv[]){
    long n,k,r;
    scanf("%ld %ld", &n,&k);
    if(n>k){
        r = n % k;
    }else{
        r = n;
    }

    if(r>n){
        printf("%ld",n);
    }else{
        printf("%ld",r);
    }


    return 0;
}