import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String str1 = sc.nextLine();
String str2 = sc.nextLine();
if(str1.length()>str2.length()){
String temp=str1;
str1=str2;
str2=temp;
} String max=""; for (int i = 0; i < str1.length(); i++) { for (int j = i; j < str1.length(); j++) { String temp = str1.substring(i,j+1); if(str2.contains(temp)){ if(temp.length()>max.length()){ max=temp; } }else { break; } } } System.out.println(max); }
}}