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.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;

public class Password {

	public static int nextMax(int max, int[] x,int indexOfMax) {
		int nextmax = 0;
		for (int i = indexOfMax+1; i < x.length; i++) {
			if (x[i] > nextmax && x[i] <= max) {
				nextmax = x[i];
			}
		}
		return nextmax;
	}

	public static int[] generateZ(String S) {
		int z[] = new int[S.length()];
		int L = 0, R = 0;
		for (int i = 1; i < S.length(); i++) {
			if (i > R) {
				L = R = i;
				while (R < S.length() && S.charAt(R - L) == S.charAt(R))
					R++;
				z[i] = R - L;
				R--;
			} else {
				int k = i - L;
				if (z[k] < R - i + 1)
					z[i] = z[k];
				else {
					L = i;
					while (R < S.length() && S.charAt(R - L) == S.charAt(R))
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		return z;
	}
	
	public static String password(String test,int max,int []Z,int MaxIndex){
		 String theSuffix = test.substring(MaxIndex, test.length());
		 //System.out.println(theSuffix);
		 String theMiddle = test.substring(1, test.length()-1);
		 String test2 = theSuffix+"$"+theMiddle;
		 //System.out.println(test2);
		 int []ZofMiddle = generateZ(test2);
		 boolean flag = false;
		 int theSuffixLength = theSuffix.length();
		 for(int i=theSuffixLength;i<test2.length();i++){
			 if(ZofMiddle[i]==theSuffixLength){
				 flag=true;
			 }
		 }
		 if(flag){
			 return theSuffix;
		 }else{
			 int []ZofSuffix = generateZ(theSuffix);
			 for(int i=0;i<ZofSuffix.length;i++){
				 if(ZofSuffix[i]+i==ZofSuffix.length&&ZofSuffix[i]!=0){
					 return theSuffix.substring(0, ZofSuffix[i]);
				 }
			 }
			 return "Just a legend"; 
			 
		 }
		 
		 
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String test = br.readLine();
		int Z[] = generateZ(test);
		boolean flag = false;
		int maxZ = 0;
		int indexMax = 0;
		//LinkedList<Integer> indexMax = new LinkedList<Integer>();
		for(int i=0;i<Z.length;i++){
			if(Z[i]+i==Z.length&&Z[i]!=0){
				indexMax=i;
				maxZ = Z[i];
			//	System.out.println(i+" "+maxZ);
				break;
			}
		}
		
		
	//	System.out.println(maxZ+" "+indexOfMax);
		if(maxZ==0){
			System.out.println("Just a legend");
		}else{
			System.out.println(password(test,maxZ,Z,indexMax));
		}
//			indexMax.addLast(test.length() - maxZ);
//			String prefix = test.substring(0, maxZ);
//			// System.out.println(prefix);
//			if (prefix.equals(test.substring((Integer) indexMax.getFirst(),
//					(Integer) indexMax.getFirst() + maxZ))
//					&& prefix.equals(test.substring(
//							(Integer) indexMax.getLast(), test.length()))
//					&& indexMax.getFirst() + maxZ != test.length()) {
//				System.out.println(prefix);
//				flag = true;
//				break;
//			} else {
//				maxZ = nextMax(maxZ, Z);
//			}
//			indexMax.clear();
//		}
//		if (flag == false) {
//			System.out.println("Just a legend");
//		}
	}
}