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.*;
import java.util.*;
public final class code
// class code
// public class Solution
{
	static void solve()throws IOException
	{
		char s[]=(" "+nextLine()).toCharArray();
		int n=s.length-1;
		int p[]=new int[n+1];
		p[1]=0;
		for(int i=2;i<=n;i++)
		{
			int j=p[i-1];
			while(j>0 && s[j+1]!=s[i])
				j=p[j];
			if(s[j+1]==s[i])
				j++;
			p[i]=j;
		}
		if(p[n]==0)
		{
			out.println("Just a legend");
			return;
		}
		for(int i=1;i<n;i++)
		{
			if(p[i]==p[n])
			{
				for(int j=1;j<=p[n];j++)
					out.print(s[j]);
				return;
			}
		}
		if(p[p[n]]==0)
			out.println("Just a legend");
		else
		{
			for(int i=1;i<=p[p[n]];i++)
				out.print(s[i]);
		}
	}
	



	
	///////////////////////////////////////////////////////////
	static final long mod=(long)(1e8);
	static final int inf=(int)(1e9);
	// static final long inf=(long)(1e18);
	static class Pair implements Comparable<Pair>
	{
		int first,second;
		Pair(int a,int b)
		{
			first=a;
			second=b;
		}
		public int compareTo(Pair p)
		{
			if(this.second==p.second)
				return this.first-p.first;
			return this.second-p.second;
		}
		public boolean equals(Pair p)
		{
			if(this.first==p.first && this.second==p.second)
				return true;
			else
				return false;
		}
	}
	static void debug(Object ... a)
	{
		System.out.print("> ");
		for(int i=0;i<a.length;i++)
			System.out.print(a[i]+" ");
		System.out.println();
	}
	static void debuga(int a[])
	{
		System.out.print("> ");
		for(int i=0;i<a.length;i++)
			System.out.print(a[i]+" ");
		System.out.println();
	}
	static Random random;
	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;
	static String nextToken()throws IOException
	{
		while(st==null || !st.hasMoreTokens())
			st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	static String nextLine()throws IOException
	{
		return br.readLine();
	}
	static int nextInt()throws IOException
	{
		return Integer.parseInt(nextToken());
	}
	static long nextLong()throws IOException
	{
		return Long.parseLong(nextToken());
	}
	static double nextDouble()throws IOException
	{
		return Double.parseDouble(nextToken());
	}
	public static void main(String args[])throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		out=new PrintWriter(new BufferedOutputStream(System.out));
		random=new Random();
		solve();

		// int t=nextInt();
		// for(int i=1;i<=t;i++)
		// {
		// 	// out.print("Case #"+i+": ");
		// 	solve();
		// }

		out.close();
	}
}