http://codeforces.com/contest/126/problem/B
#include<bits/stdc++.h>
using namespace std;
const int M = 1e6 + 10 ;
char s[M] ;
int lens ;
bool vis[M] ;
int NEXT[M] ;
void get_fail () {
NEXT[0] = -1 ;
for (int i = 1 , at = -1 ; i < lens ; i ++) {
while (at != -1 && s[at+1] != s[i]) at = NEXT[at] ;
NEXT[i] = s[at+1] == s[i] ? ++at : at ;
}
}
void solve () {
get_fail () ;
int at = NEXT[lens-1] ;
while (at != -1) {
vis[at] = 1 ;
at = NEXT[at] ;
}
int maxn = -1 ;
for (int i = lens-2 ; i >= 0 ; i --) {
if (vis[NEXT[i]]) {
if (NEXT[i] > maxn) maxn = NEXT[i] ;
}
}
if (maxn == -1) puts ("Just a legend") ;
for (int i = 0 ; i <= maxn ; i ++) printf ("%c" , s[i]) ; puts ("") ;
}
int main () {
scanf ("%s" , s) ;
lens = strlen (s) ;
solve () ;
return 0 ;
}