#include <bits/stdc++.h>
using namespace std;
int n;
string x,y;
const long long B = 100000007;
const long long M1 = 1000000007;
const long long M2 = 1000000321;
long long pb1[1000005],pb2[1000005],ipb1,ipb2;
long long power_mod(long long a,long long n,const long long M)
{
if(n==0)
return 1;
long long int ans = power_mod(a,n/2,M);
ans = (ans%M * ans%M)%M;
if(n%2==1)
ans = (ans%M * a%M)%M;
return ans;
}
int f(int l)
{
map<long long,int> mp1,mp2;
long long h1=0,h2=0;
for(int i=0;i<l;i++)
{
h1 = (h1%M1 + ((long long)(x[i])%M1*pb1[i]%M1)%M1)%M1;
h2 = (h2%M2 + ((long long)(x[i])%M2*pb2[i]%M2)%M2)%M2;
}
mp1[h1]=1;
mp2[h2]=1;
for(int i=l;i<x.size();i++)
{
h1=(h1%M1+ ((long long)(x[i])%M1*pb1[l]%M1)%M1)%M1;
h1=(h1%M1-(long long)(x[i-l])%M1+M1)%M1;
h1=(h1%M1*ipb1%M1)%M1;
mp1[h1]=1;
h2=(h2%M2+ ((long long)(x[i])%M2*pb2[l]%M2)%M2)%M2;
h2=(h2%M2-(long long)(x[i-l])%M2+M2)%M2;
h2=(h2%M2*ipb2%M2)%M2;
mp2[h2]=1;
}
h1=0,h2=0;
for(int i=0;i<l;i++)
{
h1 = (h1%M1 + ((long long)(y[i])%M1*pb1[i]%M1)%M1)%M1;
h2 = (h2%M2 + ((long long)(y[i])%M2*pb2[i]%M2)%M2)%M2;
}
if(mp1.find(h1)!=mp1.end() && mp2.find(h2) != mp2.end() )
return 0;
for(int i=l;i<y.size();i++)
{
h1=(h1%M1+ ((long long)(y[i])%M1*pb1[l]%M1)%M1)%M1;
h1=(h1%M1-(long long)(y[i-l])%M1+M1)%M1;
h1=(h1%M1*ipb1%M1)%M1;
h2=(h2%M2+ ((long long)(y[i])%M2*pb2[l]%M2)%M2)%M2;
h2=(h2%M2-(long long)(y[i-l])%M2+M2)%M2;
h2=(h2%M2*ipb2%M2)%M2;
if(mp1.find(h1)!=mp1.end() && mp2.find(h2)!=mp2.end() )
return i-l+1;
}
return -1;
}
int main()
{
pb1[0]=1LL;
pb2[0]=1LL;
for(int i=1;i<=1000000;i++)
{
pb1[i] = (pb1[i-1]%M1 * B%M1)%M1;
pb2[i] = (pb2[i-1]%M2 * B%M2)%M2;
}
ipb1 = power_mod(B,M1-2,M1);
ipb2 = power_mod(B,M2-2,M2);
cin>>x>>y;
n = min(x.size(),y.size());
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;
l=m+1;
}
else
r=m-1;
}
cout<<res<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBuOwpzdHJpbmcgeCx5Owpjb25zdCBsb25nIGxvbmcgQiA9IDEwMDAwMDAwNzsKY29uc3QgbG9uZyBsb25nIE0xID0gMTAwMDAwMDAwNzsKY29uc3QgbG9uZyBsb25nIE0yID0gMTAwMDAwMDMyMTsKbG9uZyBsb25nIHBiMVsxMDAwMDA1XSxwYjJbMTAwMDAwNV0saXBiMSxpcGIyOwpsb25nIGxvbmcgcG93ZXJfbW9kKGxvbmcgbG9uZyBhLGxvbmcgbG9uZyBuLGNvbnN0IGxvbmcgbG9uZyBNKQp7CglpZihuPT0wKQoJCXJldHVybiAxOwoJbG9uZyBsb25nIGludCBhbnMgPSBwb3dlcl9tb2QoYSxuLzIsTSk7CglhbnMgPSAoYW5zJU0gKiBhbnMlTSklTTsKCWlmKG4lMj09MSkKCQlhbnMgPSAoYW5zJU0gKiBhJU0pJU07CglyZXR1cm4gYW5zOwp9CmludCBmKGludCBsKQp7CiAgICBtYXA8bG9uZyBsb25nLGludD4gbXAxLG1wMjsKICAgIGxvbmcgbG9uZyBoMT0wLGgyPTA7CiAgICBmb3IoaW50IGk9MDtpPGw7aSsrKQogICAgewogICAgICAgIGgxID0gKGgxJU0xICsgKChsb25nIGxvbmcpKHhbaV0pJU0xKnBiMVtpXSVNMSklTTEpJU0xOwogICAgICAgIGgyID0gKGgyJU0yICsgKChsb25nIGxvbmcpKHhbaV0pJU0yKnBiMltpXSVNMiklTTIpJU0yOwogICAgfQogICAgbXAxW2gxXT0xOwogICAgbXAyW2gyXT0xOwogICAgZm9yKGludCBpPWw7aTx4LnNpemUoKTtpKyspCiAgICB7CiAgICAgICAgaDE9KGgxJU0xKyAoKGxvbmcgbG9uZykoeFtpXSklTTEqcGIxW2xdJU0xKSVNMSklTTE7CiAgICAgICAgaDE9KGgxJU0xLShsb25nIGxvbmcpKHhbaS1sXSklTTErTTEpJU0xOwogICAgICAgIGgxPShoMSVNMSppcGIxJU0xKSVNMTsKICAgICAgICBtcDFbaDFdPTE7CgogICAgICAgIGgyPShoMiVNMisgKChsb25nIGxvbmcpKHhbaV0pJU0yKnBiMltsXSVNMiklTTIpJU0yOwogICAgICAgIGgyPShoMiVNMi0obG9uZyBsb25nKSh4W2ktbF0pJU0yK00yKSVNMjsKICAgICAgICBoMj0oaDIlTTIqaXBiMiVNMiklTTI7CiAgICAgICAgbXAyW2gyXT0xOwogICAgfQogICAgaDE9MCxoMj0wOwogICAgZm9yKGludCBpPTA7aTxsO2krKykKICAgIHsKICAgICAgICBoMSA9IChoMSVNMSArICgobG9uZyBsb25nKSh5W2ldKSVNMSpwYjFbaV0lTTEpJU0xKSVNMTsKICAgICAgICBoMiA9IChoMiVNMiArICgobG9uZyBsb25nKSh5W2ldKSVNMipwYjJbaV0lTTIpJU0yKSVNMjsKICAgIH0KICAgIGlmKG1wMS5maW5kKGgxKSE9bXAxLmVuZCgpICYmIG1wMi5maW5kKGgyKSAhPSBtcDIuZW5kKCkgKQogICAgICAgIHJldHVybiAwOwogICAgZm9yKGludCBpPWw7aTx5LnNpemUoKTtpKyspCiAgICB7CiAgICAgICAgaDE9KGgxJU0xKyAoKGxvbmcgbG9uZykoeVtpXSklTTEqcGIxW2xdJU0xKSVNMSklTTE7CiAgICAgICAgaDE9KGgxJU0xLShsb25nIGxvbmcpKHlbaS1sXSklTTErTTEpJU0xOwogICAgICAgIGgxPShoMSVNMSppcGIxJU0xKSVNMTsKCiAgICAgICAgaDI9KGgyJU0yKyAoKGxvbmcgbG9uZykoeVtpXSklTTIqcGIyW2xdJU0yKSVNMiklTTI7CiAgICAgICAgaDI9KGgyJU0yLShsb25nIGxvbmcpKHlbaS1sXSklTTIrTTIpJU0yOwogICAgICAgIGgyPShoMiVNMippcGIyJU0yKSVNMjsKICAgICAgICBpZihtcDEuZmluZChoMSkhPW1wMS5lbmQoKSAmJiBtcDIuZmluZChoMikhPW1wMi5lbmQoKSApCiAgICAgICAgICAgIHJldHVybiBpLWwrMTsKICAgIH0KICAgIHJldHVybiAtMTsKfQppbnQgbWFpbigpCnsKICAgIHBiMVswXT0xTEw7CiAgICBwYjJbMF09MUxMOwogICAgZm9yKGludCBpPTE7aTw9MTAwMDAwMDtpKyspCiAgICB7CiAgICAgICAgcGIxW2ldID0gKHBiMVtpLTFdJU0xICogQiVNMSklTTE7CiAgICAgICAgcGIyW2ldID0gKHBiMltpLTFdJU0yICogQiVNMiklTTI7CiAgICB9CgogICAgaXBiMSA9IHBvd2VyX21vZChCLE0xLTIsTTEpOwogICAgaXBiMiA9IHBvd2VyX21vZChCLE0yLTIsTTIpOwoJY2luPj54Pj55OwogICAgbiA9IG1pbih4LnNpemUoKSx5LnNpemUoKSk7CiAgICBpbnQgbD0xLHI9bixtLHJlcz0tMSxzdDsKICAgIHdoaWxlKGw8PXIpCiAgICB7CiAgICAgICAgbSA9IChsK3IpLzI7CiAgICAgICAgaW50IHJyPWYobSk7CiAgICAgICAgaWYocnIhPS0xKQogICAgICAgIHsKICAgICAgICAgICAgcmVzPW07CiAgICAgICAgICAgIGw9bSsxOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgICAgIHI9bS0xOwogICAgfQogICAgY291dDw8cmVzPDxlbmRsOwoJcmV0dXJuIDA7Cn0K