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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.util.ArrayList;
public class B126 
{
    static class Scanner
    {
        BufferedReader br;
        StringTokenizer tk=new StringTokenizer("");
        public Scanner(InputStream is) 
        {
            br=new BufferedReader(new InputStreamReader(is));
        }
        public int nextInt() throws IOException
        {
            if(tk.hasMoreTokens())
                return Integer.parseInt(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextInt();
        }
        public long nextLong() throws IOException
        {
            if(tk.hasMoreTokens())
                return Long.parseLong(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextLong();
        }
        public String next() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return next();
        }
        public String nextLine() throws IOException
        {
            tk=new StringTokenizer("");
            return br.readLine();
        }
        public double nextDouble() throws IOException
        {
            if(tk.hasMoreTokens())
                return Double.parseDouble(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextDouble();
        }
        public char nextChar() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken().charAt(0));
            tk=new StringTokenizer(br.readLine());
            return nextChar();
        }
        public int[] nextIntArray(int n) throws IOException
        {
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArray(int n) throws IOException
        {
            long a[]=new long[n];
            for(int i=0;i<n;i++)
                a[i]=nextLong();
            return a;
        }
        public int[] nextIntArrayOneBased(int n) throws IOException
        {
            int a[]=new int[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArrayOneBased(int n) throws IOException
        {
            long a[]=new long[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextLong();
            return a;
        }
    
    
    }
    static long mod=1000000007;
    static long inv(long b)
    {
        long e=mod-2;
        long res=1;
        while(e>0)
        {
            if(e%2==1)
                res=(res*b)%mod;
            b*=b;
            b%=mod;
            e/=2;
        }
        return res;
    }
    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        char c[]=("0"+in.next()).toCharArray();
        c[0]=0;
        long p[]=new long[c.length];
        long inv[]=new long[c.length];
        inv[0]=1;
        p[0]=1;
        long hh=inv(101);
        for(int i=1;i<c.length;i++)
        {
            p[i]=(101*p[i-1])%mod;
            inv[i]=(hh*inv[i-1])%mod;
        }
        
        long h[]=new long[c.length];
        for(int i=1;i<c.length;i++)
            h[i]=(h[i-1]+c[i]*p[i])%mod;
        int n=c.length-1;
        ArrayList<Integer> ar=new ArrayList<>();
        for(int i=1;i<n;i++)
        {
            long h1=h[i];
            long h2=h[n]-h[n-i];
            h2*=inv[n-i];
            h2%=mod;
            if(h2<0)
                h2+=mod;
            if(h1==h2)
                ar.add(i);
        }
        int ans=0;
        int lo=0,hi=ar.size()-1;
        while(lo<=hi)
        {
            int mid=(lo+hi)/2;
            int val=ar.get(mid);
            //max match length is val;
            boolean match=false;
            for(int i=2;i<=n;i++)
            {
                if(i+val-1>=n)
                    break;
                long h1=h[val];
                long h2=h[i+val-1]-h[i-1];
                h2*=inv[i-1];
                h2%=mod;
                if(h2<0)
                    h2+=mod;
                if(h1==h2)
                {
                    match=true;
                    break;
                }
            }
            if(match)
            {
                ans=Math.max(ans,val);
                lo=mid+1;
            }
            else
                hi=mid-1;
        }
        if(ans!=0)
            out.println(new String(c,1,ans));
        else
            out.println("Just a legend");
        out.close();
    }

}