import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		// a > b ??¨????????¢????????????
		if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long d = 0; // d : gcd(a,b)
		while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		}

		System.out.println(d);
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		// a > b ??¨????????¢????????????
		if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long d = 0; // d : gcd(a,b)
		while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		}

		System.out.println(d);
	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		// a > b ??¨????????¢????????????
		if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long d = 0; // d : gcd(a,b)
		while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		}

		System.out.println(d);
	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		// a > b ??¨????????¢????????????
		if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long d = 0; // d : gcd(a,b)
		while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		}

		System.out.println(d);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong(); a sc.nextLong() sc.nextLong sc long b = sc.nextLong(); b sc.nextLong() sc.nextLong sc if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		} a < b a b {
			long temp = a;
			a = b;
			b = temp;
		} long temp = a; temp a a = b a b b = temp b temp long d = 0; d 0 while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		} true {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		} long r = a % b; r a % b a b if (r == 0) {
				d = b;
				break;
			} r == 0 r 0 {
				d = b;
				break;
			} d = b d b break; a = b a b b = r b r System.out.println(d) System.out.println System.out System System.out d String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		// a > b ??¨????????¢????????????
		if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long d = 0; // d : gcd(a,b)
		while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		}

		System.out.println(d);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		// a > b ??¨????????¢????????????
		if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long d = 0; // d : gcd(a,b)
		while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		}

		System.out.println(d);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		// a > b ??¨????????¢????????????
		if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long d = 0; // d : gcd(a,b)
		while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		}

		System.out.println(d);
	}

}