import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int a, b;
        a = input.nextInt();
        b = input.nextInt();
        System.out.println(gcd(a, b));
    }   
    
    static int gcd(int x, int y) {
        while (x > 0 && y > 0) {
            if (x > y) x %= y; else y %= x;
        }
        return x + y;
    }
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int a, b;
        a = input.nextInt();
        b = input.nextInt();
        System.out.println(gcd(a, b));
    }   
    
    static int gcd(int x, int y) {
        while (x > 0 && y > 0) {
            if (x > y) x %= y; else y %= x;
        }
        return x + y;
    }
} Main static final int INF = 1000000000; INF 1000000000 public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int a, b;
        a = input.nextInt();
        b = input.nextInt();
        System.out.println(gcd(a, b));
    } main {                
        Scanner input = new Scanner(System.in);
        int a, b;
        a = input.nextInt();
        b = input.nextInt();
        System.out.println(gcd(a, b));
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int a a b; b a = input.nextInt() a input.nextInt() input.nextInt input b = input.nextInt() b input.nextInt() input.nextInt input System.out.println(gcd(a, b)) System.out.println System.out System System.out gcd(a, b) gcd a b String[] args args static int gcd(int x, int y) {
        while (x > 0 && y > 0) {
            if (x > y) x %= y; else y %= x;
        }
        return x + y;
    } gcd {
        while (x > 0 && y > 0) {
            if (x > y) x %= y; else y %= x;
        }
        return x + y;
    } while (x > 0 && y > 0) {
            if (x > y) x %= y; else y %= x;
        } x > 0 && y > 0 x > 0 x 0 y > 0 y 0 {
            if (x > y) x %= y; else y %= x;
        } if (x > y) x %= y; else y %= x; x > y x y x %= y x y y %= x y x return x + y; x + y x y int x x int y y public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int a, b;
        a = input.nextInt();
        b = input.nextInt();
        System.out.println(gcd(a, b));
    }   
    
    static int gcd(int x, int y) {
        while (x > 0 && y > 0) {
            if (x > y) x %= y; else y %= x;
        }
        return x + y;
    }
} public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int a, b;
        a = input.nextInt();
        b = input.nextInt();
        System.out.println(gcd(a, b));
    }   
    
    static int gcd(int x, int y) {
        while (x > 0 && y > 0) {
            if (x > y) x %= y; else y %= x;
        }
        return x + y;
    }
} Main
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int a, b;
        a = input.nextInt();
        b = input.nextInt();
        System.out.println(gcd(a, b));
    }   
    
    static int gcd(int x, int y) {
        while (x > 0 && y > 0) {
            if (x > y) x %= y; else y %= x;
        }
        return x + y;
    }
}