// Arup Guha
// 8/2/2026
// Solution to 1990 UCF HS Programming Contest Problem: Damaged Digit Display

import java.util.*;

public class digit {
	
	// Pre-compute, a = 1, b = 2, c = 4, d = 8, etc.
	final public static int MA = 1;
	final public static int MB = 2;
	final public static int MC = 4;
	final public static int MD = 8;
	final public static int ME = 16;
	final public static int MF = 32;
	final public static int MG = 64;
	final public static int ALL = 127;
	final public static int[] MASKS = {ALL-MD, MC+MF, ALL-MB-MF, ALL-MB-ME, ALL-MA-ME-MG,
									   ALL-MC-ME, ALL-MC, MA+MC+MF, ALL, ALL-ME};
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);	
		while (stdin.hasNext()) {
		
			// Get input, convert to masks.
			String broken = stdin.next();
			String on = stdin.next();
			int maskB = getMask(broken);
			int maskO = getMask(on);
			
			// Just go in order.
			for (int i=0; i<MASKS.length; i++) {
			
				// These bits have to be on in the real number.
				if ((MASKS[i] & maskO) != maskO) continue;
				
				// Isolates other bits than the ones that are currently on in
				// actual representation of i.
				int left = MASKS[i] - maskO;
				
				// Only now is it possible.
				if ((left & maskB) == left)
					System.out.printf("%5d", i);
			}
			System.out.println();
		}
	}
	
	// Returns s as a mask.
	public static int getMask(String s) {
		int res = 0;
		
		// Just shift by the appropriate ordinal value and add to accumulator.
		for (int i=0; i<s.length(); i++)
			res += (1<<(s.charAt(i)-'a'));
		return res;
	}
}