import java.util.*; public class Kyosaya{ public static void main(String args[]) { Scanner s=new Scanner(System.in); int pocky = s.nextInt(); int gnaw = s.nextInt(); if(gnaw*2>= pocky){ System.out.println(0); }else{ int result = pocky-(pocky-(pocky/gnaw/2)*gnaw); if(result*2 == pocky){ result= result - gnaw; } System.out.println(result); } } }