package com.javarush.task.task14.task1420;

/*
НОД
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;

public class Solution {
    private static ArrayList<Integer> listA = new ArrayList<Integer>();
    private static ArrayList<Integer> listB = new ArrayList<Integer>();
    private static ArrayList<Integer> listC = new ArrayList<Integer>(listA);

    public static void main(String[] args) throws Exception {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(reader.readLine());
        int b = Integer.parseInt(reader.readLine());
        delete(a,b);;
        listC.retainAll(listB); // почему вот это не работает!?!?!-------------------------------------------------------------------------------------------
        for(Integer pare:listC){
            System.out.println(pare);
        }

    }

    public static void delete(int a,int b) {
        while (a != 1) {
            if (a % 2 == 0) {
                a = a / 2;
                listA.add(2);
            }
            if (a % 3 == 0) {
                a = a / 3;
                listA.add(3);
            }
            if (a % 5 == 0) {
                a = a / 5;
                listA.add(5);
            }
            if (a % 7 == 0) {
                a = a / 7;
                listA.add(7);
            }
           else {listA.add(a); break;}
        }


            while (b != 1) {
            if (b % 2 == 0) {
                b = b / 2;
                listB.add(2);
            }
            if (b % 3 == 0) {
                b = b / 3;
                listB.add(3);
            }
            if (b % 5 == 0) {
                b = b / 5;
                listB.add(5);
            }
            if (b % 7 == 0) {
                b = b / 7;
                listB.add(7);
            }
            else{
                listB.add(b);
                break;
            }

        }

        }



}