#include <stdio.h>

int main()
{
  int x,k,n1,n2,next=1;
  int min,p,now;
  scanf("%d",&x);
  scanf("%d",&k);
  
  if(x>k){
    n1 = x; 
    n2 = k;
    p = 0;
  }
  else{
    n1 = k;
    n2 = x;
    p = 1;
  }
  min = x;
  while(next==1){
    now = n1 - n2;
    if(now<=0)
      next = 0;
    min = now;
    if(p==0) n1 = now;
    else n2 = now;
  }
  if(min<x) printf("%d",min*-1);
  else printf("%d",x);
  return 0;
}