#include <iostream>

using namespace std;

int main(){
    string ls,ss;
    while (cin>>ls>>ss){
        if (ls.size()<ss.size()) swap(ls,ss);
        int n = ss.size();
        bool flag = false;
        while (n--){
            if (flag) break;
            for (int i = 0; i <= ss.size()-n; ++i) {
                string tem = ss.substr(i,n);
                if (ls.find(tem) != string::npos){
                    cout<<tem<<endl;
                    flag = true;
                    break;
                }
            }
        }
    }
    return 0;
}