import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static String dfs(String part, int pick, int sum, String[] yuki, String[] coder){ //System.out.println(part + " : " + pick); if(pick >= sum){ return part; } else if(part.length() <= pick){ return null; } final char pick_ch = part.charAt(pick); final String for_next = part.substring(0, pick); for(final String y : yuki){ if(y.charAt(0) != pick_ch){ continue; } final String ret = dfs(for_next + y, pick + 1, sum, yuki, coder); if(ret != null){ return ret; } } for(final String c : coder){ if(c.charAt(0) != pick_ch){ continue; } final String ret = dfs(for_next + c, pick + 1, sum, yuki, coder); if(ret != null){ return ret; } } return dfs(part, pick + 1, sum, yuki, coder); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); String[] yuki = new String[N]; for(int i = 0; i < N; i++){ yuki[i] = sc.next(); } final int M = sc.nextInt(); String[] coder = new String[M]; for(int i = 0; i < M; i++){ coder[i] = sc.next(); } int sum = 0; for(final String y : yuki){ sum += y.length(); } if(N == 1 && M == 1){ System.out.println(yuki[0].equals(coder[0]) ? yuki[0] : "-1"); return; } String answer = null; for(final String y : yuki){ if(y.length() == 1){ continue; } final String ret = dfs(y, 1, sum, yuki, coder); if(ret != null){ answer = ret; } } for(final String c : coder){ if(c.length() == 1){ continue; } final String ret = dfs(c, 1, sum, yuki, coder); if(ret != null){ answer = ret; } } System.out.println(answer == null ? "-1" : answer); } }