#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    string s1, s2;
    while(cin >> s1 >> s2)
    {
        if(s1.length() > s2.length()) swap(s1, s2);
        string ans = "";
        for(int i = 0; i < s1.length(); i++)
            for(int j = 0; j < s2.length(); j++)
            {
                int l = 0;
                for(;i+l<s1.length() && j+l<s2.length() && s1[i+l]==s2[j+l];l++);
                if(ans.length() < l)ans = s1.substr(i, l);
            }
        cout << ans << endl;
    }
}