import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String s2 = sc.nextLine();
        if (s1.length() > s2.length()) {
            // 确保s1比较短
            String tmp = s1;
            s1 = s2;
            s2 = tmp;
        }
        // 存储最长子串
        String result = "";
        // 左指针
        int left = 0;
        // 右指针,从第一个字符开始移动
        int right = left + 1;
        while (right <= s1.length()) {
            String tmp = s1.substring(left, right);
            if (s2.contains(tmp)) {
                if (result.length() < tmp.length()) {
                    result = tmp;
                }
                // 是子串的情况下,只移动右指针
                right++;
            } else {
                // 左指针移动一位
                left++;
                right = left + 1;
            }
        }
        System.out.println(result);
    }
}