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

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		Integer x = Integer.parseInt(s.next());
		Integer y = Integer.parseInt(s.next());
		s.close();
		if(x > y){
			Integer remain = x % y;
			Integer new_remain = y % remain;
			Integer bkp = 0;
			while(new_remain > 0){
				bkp = new_remain;
				new_remain = remain % new_remain;
			}
			System.out.println(bkp);
		}
		else if(y > x){
			Integer remain = y % x;
			Integer new_remain = x % remain;
			Integer bkp = 0;
			while(new_remain > 0){
				bkp = new_remain;
				new_remain = remain % new_remain;
			}
			System.out.println(bkp);
		}
		else{
			System.out.println(y);
		}
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz