#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> z_algo(){
int n = s.length();
vector<int>z(n,0);
int L = 0, R = 0;
for (int i = 1; i < n; i++) {
if (i > R) {
L = R = i;
while (R < n && s[R-L] == s[R]) R++;
z[i] = R-L; R--;
}
else {
int k = i-L;
if (z[k] < R-i+1) z[i] = z[k];
else {
L = i;
while (R < n && s[R-L] == s[R]) R++;
z[i] = R-L; R--;
}
}
}
return z;
}
int main(){
cin>>s;int n=s.size();
if(s.size() < 3){cout<<"Just a legend";return 0;}
vector<int>z = z_algo();
vector<int >::iterator it=z.begin();
//for(int i=0;i<z.size();i++){
// z[i].push_back(i);
//}
int first=-1,second=-1;//store top two value indexes
int maxi=-1,maxii=-1,i;
for(i=0;it!=z.end();it++,i++){
if((*it) > maxi){maxi=(*it);first=i;}
//if((*it) > maxii)maxii=(*it),second=i;
}
it=z.begin();
for(i=0;it!=z.end();it++,i++){
//if((*it) > maxi){maxi=(*it);first=i;}
if(i==first)continue;
if((*it) > maxii)maxii=(*it),second=i;
}
//sort(z.begin(),z.end());
//f//or(i=0;i<z.size();i++){
// cout<<z[i];
// }
/*
int counter=0;
bool flag=false;
cout<<first<<second<<maxi<<maxii;
if(maxii==0 || maxi==0){cout<<"Just a legend";return 0;}
if(first>second){cout<<"Just a legend";return 0;}
else{flag=true;
for(i=first;counter<maxii;counter++,i++){
cout<<s[i];//cout<<"HIU";
}
return 0;
}
if(!flag){cout<<"Just a legend";}
else{
}
*/
int counter =0;
string match = "";
for(i=first;counter<maxii;counter++,i++){
match+=s[i];
}
bool flag=true;
for(i=0;i<maxii;i++){
if(match[i]!=s[i]){flag=false;break;}
}
if(!flag){cout<<"Just a legend";return 0;}
counter=0;
for(i=n-maxii;counter<n-maxii,i<n;i++,counter++){
if(match[counter]!=s[i]){flag=false;break;}
}
//cout<<first<<second<<maxi<<maxii;
if(!flag){cout<<"Just a legend";return 0;}
else{
if(match=="")cout<<"Just a legend";
else{
cout<<match;
}
}
return 0;
}
I2luY2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