#include <iostream>
#include <cstring>
using namespace std;
const int N=2e6+10;
int ne[N];
char s[N];
void kmp(char s[]) {
int len=strlen(s+1);
for(int i=2,j=0; i<=len; i++) {
while(j&&s[i]!=s[j+1]) j=ne[j];
if(s[i]==s[j+1]) j++;
ne[i]=j;
}
}
signed main() {
gets(s+1);
int len=strlen(s+1);
if(len<3) {
cout<<"Just a legend";
return 0;
}
kmp(s);
int ans=0;
for(int i=2; i<len; i++)
if(s[i]==s[len]&&ne[i]<=ne[len]) {
ans=max(ans,ne[i]);
}
if(ans==0) cout<<"Just a legend";
else for(int i=1; i<=ans; i++) cout<<s[i];
return 0;
}