import java.util.Scanner;

/**
 * Created by shoya on 2017/04/11.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println(GCJ(sc.nextInt(), sc.nextInt()));
    }

    static int GCJ(int a, int b){
        if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0)
            return a;
        else
            return GCJ(b, a % b);
    }

} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println(GCJ(sc.nextInt(), sc.nextInt()));
    }

    static int GCJ(int a, int b){
        if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0)
            return a;
        else
            return GCJ(b, a % b);
    }

} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println(GCJ(sc.nextInt(), sc.nextInt()));
    } main {
        Scanner sc = new Scanner(System.in);
        System.out.println(GCJ(sc.nextInt(), sc.nextInt()));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) System.out.println(GCJ(sc.nextInt(), sc.nextInt())) System.out.println System.out System System.out GCJ(sc.nextInt(), sc.nextInt()) GCJ sc.nextInt() sc.nextInt sc sc.nextInt() sc.nextInt sc String[] args args static int GCJ(int a, int b){
        if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0)
            return a;
        else
            return GCJ(b, a % b);
    } GCJ {
        if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0)
            return a;
        else
            return GCJ(b, a % b);
    } if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        } a < b a b {
            int tmp = a;
            a = b;
            b = tmp;
        } int tmp = a; tmp a a = b a b b = tmp b tmp if (b == 0)
            return a;
        else
            return GCJ(b, a % b); b == 0 b 0 return a; a return GCJ(b, a % b); GCJ(b, a % b) GCJ b a % b a b int a a int b b public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println(GCJ(sc.nextInt(), sc.nextInt()));
    }

    static int GCJ(int a, int b){
        if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0)
            return a;
        else
            return GCJ(b, a % b);
    }

} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println(GCJ(sc.nextInt(), sc.nextInt()));
    }

    static int GCJ(int a, int b){
        if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0)
            return a;
        else
            return GCJ(b, a % b);
    }

} Main
import java.util.Scanner;

/**
 * Created by shoya on 2017/04/11.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println(GCJ(sc.nextInt(), sc.nextInt()));
    }

    static int GCJ(int a, int b){
        if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0)
            return a;
        else
            return GCJ(b, a % b);
    }

}