import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		System.out.println(getGCD(a, b));

	}

	public static int getGCD(int a, int b) {
		if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		System.out.println(getGCD(a, b));

	}

	public static int getGCD(int a, int b) {
		if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a);
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		System.out.println(getGCD(a, b));

	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		System.out.println(getGCD(a, b));

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] strArray = br.readLine().split(" "); strArray br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int a = Integer.parseInt(strArray[0]); a Integer.parseInt(strArray[0]) Integer.parseInt Integer strArray[0] strArray 0 int b = Integer.parseInt(strArray[1]); b Integer.parseInt(strArray[1]) Integer.parseInt Integer strArray[1] strArray 1 System.out.println(getGCD(a, b)) System.out.println System.out System System.out getGCD(a, b) getGCD a b String[] args args public static int getGCD(int a, int b) {
		if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a);
	} getGCD {
		if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a);
	} if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a); a == b a b return a; a if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a); a < b a b {
			return getGCD(a, b - a);
		} return getGCD(a, b - a); getGCD(a, b - a) getGCD a b - a b a return getGCD(a - b, a); getGCD(a - b, a) getGCD a - b a b a int a a int b b public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		System.out.println(getGCD(a, b));

	}

	public static int getGCD(int a, int b) {
		if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a);
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		System.out.println(getGCD(a, b));

	}

	public static int getGCD(int a, int b) {
		if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		System.out.println(getGCD(a, b));

	}

	public static int getGCD(int a, int b) {
		if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a);
	}
}