public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int x, y;
    int tmp;

    x = sc.nextInt();
    y = sc.nextInt();

    for(;;){
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    }
/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int x, y;
    int tmp;

    x = sc.nextInt();
    y = sc.nextInt();

    for(;;){
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    }
/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} Main public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int x, y;
    int tmp;

    x = sc.nextInt();
    y = sc.nextInt();

    for(;;){
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    }
/*fin*/
    sc.close();
  } run {
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int x, y;
    int tmp;

    x = sc.nextInt();
    y = sc.nextInt();

    for(;;){
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    }
/*fin*/
    sc.close();
  } java.util.Scanner sc = new java.util.Scanner(in); sc new java.util.Scanner(in) int x x y; y int tmp; tmp x = sc.nextInt() x sc.nextInt() sc.nextInt sc y = sc.nextInt() y sc.nextInt() sc.nextInt sc for(;;){
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    } ; {
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    } {
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    } if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      } x < y x y {
        tmp = x;
        x = y;
        y = tmp;
      } tmp = x tmp x x = y x y y = tmp y tmp tmp = y tmp y y = x % y y x % y x y x = tmp x tmp if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      } x == 0 || y == 0 x == 0 x 0 y == 0 y 0 {
        System.out.println(x + y);
        break;
      } System.out.println(x + y) System.out.println System.out System System.out x + y x y break; sc.close() sc.close sc java.io.InputStream in in java.io.PrintStream out out public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  } main {
    (new Main()).run(System.in, System.out);
  } (new Main()).run(System.in, System.out) (new Main()).run (new Main()) System.in System System.in System.out System System.out String[] args args public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int x, y;
    int tmp;

    x = sc.nextInt();
    y = sc.nextInt();

    for(;;){
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    }
/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int x, y;
    int tmp;

    x = sc.nextInt();
    y = sc.nextInt();

    for(;;){
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    }
/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} Main
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int x, y;
    int tmp;

    x = sc.nextInt();
    y = sc.nextInt();

    for(;;){
      if(x < y){
        tmp = x;
        x = y;
        y = tmp;
      }
      tmp = y;
      y = x % y;
      x = tmp;
      if(x == 0 || y == 0){
        System.out.println(x + y);
        break;
      }
    }
/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}