#include <bits/stdc++.h>
using namespace std;
int n;
string x,y;
const long long B = 26;
const long long M = 1000000007;
long long pb[100005],ipb;
long long power_mod(long long a,long long n)
{
if(n==0)
return 1;
long long int ans = power_mod(a,n/2);
ans = (ans%M * ans%M)%M;
if(n%2==1)
ans = (ans%M * a%M)%M;
return ans;
}
int f(int l)
{
unordered_map<long long,int> mp;
long long h=0;
for(int i=0;i<l;i++)
{
h = (h%M + ((long long)(x[i]-'a'+1)%M*pb[i]%M)%M)%M;
}
mp[h]=1;
for(int i=l;i<n;i++)
{
h=(h%M+ ((long long)(x[i]-'a'+1)%M*pb[l]%M)%M)%M;
h=(h%M-(long long)(x[i-l]-'a'+1)%M+M)%M;
h=(h%M*ipb%M)%M;
mp[h]=1;
}
h=0;
for(int i=0;i<l;i++)
{
h = (h%M + ((long long)(y[i]-'a'+1)%M*pb[i]%M)%M)%M;
}
if(mp.find(h)!=mp.end())
return 0;
for(int i=l;i<n;i++)
{
h=(h%M+ ((long long)(y[i]-'a'+1)%M*pb[l]%M)%M)%M;
h=(h%M-(long long)(y[i-l]-'a'+1)%M+M)%M;
h=(h%M*ipb%M)%M;
if(mp.find(h)!=mp.end())
return i-l+1;
}
return -1;
}
int main()
{
pb[0]=1;
for(int i=1;i<=100000;i++)
pb[i] = (pb[i-1]%M * B%M)%M;
ipb = power_mod(B,M-2);
cin>>n>>x>>y;
int l=1,r=n,m,res=-1,st;
while(l<=r)
{
m = (l+r)/2;
int rr=f(m);
if(rr!=-1)
{
res=m;
st=rr;
l=m+1;
}
else
r=m-1;
}
cout<<y.substr(st,res)<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBuOwpzdHJpbmcgeCx5Owpjb25zdCBsb25nIGxvbmcgQiA9IDI2Owpjb25zdCBsb25nIGxvbmcgTSA9IDEwMDAwMDAwMDc7CmxvbmcgbG9uZyBwYlsxMDAwMDVdLGlwYjsKbG9uZyBsb25nIHBvd2VyX21vZChsb25nIGxvbmcgYSxsb25nIGxvbmcgbikKewoJaWYobj09MCkKCQlyZXR1cm4gMTsKCWxvbmcgbG9uZyBpbnQgYW5zID0gcG93ZXJfbW9kKGEsbi8yKTsKCWFucyA9IChhbnMlTSAqIGFucyVNKSVNOwoJaWYobiUyPT0xKQoJCWFucyA9IChhbnMlTSAqIGElTSklTTsKCXJldHVybiBhbnM7Cn0KaW50IGYoaW50IGwpCnsKICAgIHVub3JkZXJlZF9tYXA8bG9uZyBsb25nLGludD4gbXA7CiAgICBsb25nIGxvbmcgaD0wOwogICAgZm9yKGludCBpPTA7aTxsO2krKykKICAgIHsKICAgICAgICBoID0gKGglTSArICgobG9uZyBsb25nKSh4W2ldLSdhJysxKSVNKnBiW2ldJU0pJU0pJU07CiAgICB9CiAgICBtcFtoXT0xOwogICAgZm9yKGludCBpPWw7aTxuO2krKykKICAgIHsKICAgICAgICBoPShoJU0rICgobG9uZyBsb25nKSh4W2ldLSdhJysxKSVNKnBiW2xdJU0pJU0pJU07CiAgICAgICAgaD0oaCVNLShsb25nIGxvbmcpKHhbaS1sXS0nYScrMSklTStNKSVNOwogICAgICAgIGg9KGglTSppcGIlTSklTTsKICAgICAgICBtcFtoXT0xOwogICAgfQogICAgaD0wOwogICAgZm9yKGludCBpPTA7aTxsO2krKykKICAgIHsKICAgICAgICBoID0gKGglTSArICgobG9uZyBsb25nKSh5W2ldLSdhJysxKSVNKnBiW2ldJU0pJU0pJU07CiAgICB9CiAgICBpZihtcC5maW5kKGgpIT1tcC5lbmQoKSkKICAgICAgICByZXR1cm4gMDsKICAgIGZvcihpbnQgaT1sO2k8bjtpKyspCiAgICB7CiAgICAgICAgaD0oaCVNKyAoKGxvbmcgbG9uZykoeVtpXS0nYScrMSklTSpwYltsXSVNKSVNKSVNOwogICAgICAgIGg9KGglTS0obG9uZyBsb25nKSh5W2ktbF0tJ2EnKzEpJU0rTSklTTsKICAgICAgICBoPShoJU0qaXBiJU0pJU07CgogICAgICAgIGlmKG1wLmZpbmQoaCkhPW1wLmVuZCgpKQogICAgICAgIHJldHVybiBpLWwrMTsKICAgIH0KICAgIHJldHVybiAtMTsKfQppbnQgbWFpbigpCnsKICAgIHBiWzBdPTE7CiAgICBmb3IoaW50IGk9MTtpPD0xMDAwMDA7aSsrKQogICAgICAgIHBiW2ldID0gKHBiW2ktMV0lTSAqIEIlTSklTTsKICAgIGlwYiA9IHBvd2VyX21vZChCLE0tMik7CgljaW4+Pm4+Png+Pnk7CiAgICBpbnQgbD0xLHI9bixtLHJlcz0tMSxzdDsKICAgIHdoaWxlKGw8PXIpCiAgICB7CiAgICAgICAgbSA9IChsK3IpLzI7CiAgICAgICAgaW50IHJyPWYobSk7CiAgICAgICAgaWYocnIhPS0xKQogICAgICAgIHsKICAgICAgICAgICAgcmVzPW07CiAgICAgICAgICAgIHN0PXJyOwogICAgICAgICAgICBsPW0rMTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgICAgICByPW0tMTsKICAgIH0KICAgIGNvdXQ8PHkuc3Vic3RyKHN0LHJlcyk8PGVuZGw7CglyZXR1cm4gMDsKfQo=