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

public class basestring_ab implements Runnable {

	private void solve() throws IOException {
		String s = checkFormat(in.readLine());
		String t = checkFormat(in.readLine());
		int q = gcd(s.length(), t.length());
		String all = s + t;
		for (int i = 0; i < all.length(); ++i) {
			if (all.charAt(i) != all.charAt(i % q)) {
				out.println("NO");
				return;
			}
		}
		out.println(s.substring(0, q));
	}

	int gcd(int a, int b) {
		if (a == 0) return b;
		return gcd(b % a, a);
	}
	
	private String checkFormat(String s) {
		assert 1 <= s.length() && s.length() <= MAX;
		for (int i = 0; i < s.length(); ++i) {
			assert 'a' <= s.charAt(i) && s.charAt(i) <= 'z';
		}
		return s;
	}

	final int MAX = (int) 1e6;
	final int INF = (int) 1e9;

	SimpleScanner in;
	PrintWriter out;

	@Override
	public void run() {
		try {
			in = new SimpleScanner(new FileReader("basestring.in"));
			out = new PrintWriter("basestring.out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new basestring_ab()).start();
	}

	class SimpleScanner extends BufferedReader {

		private StringTokenizer st;
		private boolean eof;

		public SimpleScanner(Reader a) {
			super(a);
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(readLine());
				} catch (Exception e) {
					eof = true;
					return "";
				}
			}
			return st.nextToken();
		}

		boolean seekEof() {
			String s = next();
			if ("".equals(s) && eof)
				return true;
			st = new StringTokenizer(s + " " + st.toString());
			return false;
		}

		private String cnv(String s) {
			if (s.length() == 0)
				return "0";
			return s;
		}

		int nextInt() {
			return Integer.parseInt(cnv(next()));
		}

		double nextDouble() {
			return Double.parseDouble(cnv(next()));
		}

		long nextLong() {
			return Long.parseLong(cnv(next()));
		}
	}
}