#include<stdio.h>
#include<math.h>
int main(void){
long long int n,k,ans1=0,m,s,sum=0;
  scanf("%lld%lld",&n,&k);
  ans1=n;
  if(k==1||(n%2==0&&n%2==0)){
    printf("0");
    return 0;
    
  }
  if(n%2==1&&n%2==0){
    printf("1");
    return 0;
  }
  if(n%2==0&&n%2==1){
    print("2");
    return 0;
  }
  return 0;
}