Problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.

Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.

Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened. 

You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

Input

You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

Output

Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

Examples

Input

fixprefixsuffix


Output

fix

Input

abcdabc


Output

Just a legend

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
//import java.math.*;

public class Task{
        //  ..............code begins here..............

static long mod=(long)1e9+7;
static int kmp(String s2){
        int n=s2.length();
        int[] p=new int[n];
        for(int i=1;i<n;i++){
            int j=p[i-1];
            char c1=s2.charAt(j),c2=s2.charAt(i);
            while(j>0&&c1!=c2){
                j=p[j-1];c1=s2.charAt(j);
            }
            if(c1==c2) j++;
            p[i]=j;
        }
        return p[n-1];
}
static int kmp1(String s2){
        int n=s2.length();
        int[] p=new int[n];int max=0;
        for(int i=1;i<n;i++){
            int j=p[i-1];
            char c1=s2.charAt(j),c2=s2.charAt(i);
            while(j>0&&c1!=c2){
                j=p[j-1];c1=s2.charAt(j);
            }
            if(c1==c2) j++;
            p[i]=j;
            max=Math.max(max,p[i]);
        }
        return max;
}
static void solve() throws  IOException {
            String s=read();
            if(s.length()==1){out.write("Just a legend");return;}
            int x=kmp1(s.substring(0,s.length()-1));
            StringBuilder sb=new StringBuilder(s.substring(0,x));
            sb.append("#");sb.append(s);
            int y=kmp(sb.toString());
            if(y==0||x==0) out.write("Just a legend");
            else out.write(s.substring(0,y)+"");
}
   
public static void main(String[] args) throws  IOException{
                assign();
                int t=1;//int_v(read());
                while(t--!=0) solve();
                out.flush();
}

// taking inputs

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static void sort(int[] a){List<Integer> l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i<a.length;i++){a[i]=l.get(i);}}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//static String setpreciosion(double d,int k){BigDecimal d1 = new BigDecimal(Double.toString(d));return d1.setScale(k,RoundingMode.HALF_UP).toString();}//UP DOWN HALF_UP
static int gcd(int a,int b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
//static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
//static long[] f;
}