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 class Password
{
	static long[][] mp;
	static long[] mods = {1_000_000_007, 1_000_000_009};

	public static void main(String[] args)
	{
		JS scan = new JS();
		
		mp = new long[2][1_000_001];
		mp[0][0] = mp[1][0] = 1;
		for(int i = 1; i < mp[0].length; i++) {
			for(int j = 0; j < 2; j++) {
				mp[j][i] = (mp[j][i-1]*27)%mods[j]; 
			}
		}
		
//		ArrayList<Integer> ok = new ArrayList<Integer>();
		ArrayList<Hash> hashes = new ArrayList<Hash>();
		char[] s = scan.next().toCharArray();
		int n = s.length;
		
		Hash pre = new Hash();
		Hash suf = new Hash();
		for(int i = 0; i < n-2; i++) {
			pre.add(s[i]-'a');
			suf.addFirst(s[n-i-1]-'a');
			if(pre.equal(suf)) {
				hashes.add(pre.copy());
			}
		}
		
		int res = -1;
		int lo = 0;
		int hi = hashes.size()-1;
		while(lo <= hi) {
			int mid = (lo+hi)/2;
			Hash compare = hashes.get(mid);
			int testLen = compare.len;
			Hash curr = new Hash();
			for(int i = 0; i < testLen; i++)
				curr.add(s[i]-'a');
//			System.out.println("test "+testLen);
//			System.out.println(hashes.get(mid).hash[0]);
			
			boolean good = false;
			for(int i = testLen; i < n-1; i++) {
				curr.removeFirst(s[i-testLen]-'a');
				curr.add(s[i]-'a');
//				System.out.println(curr.hash[0]);
				if(curr.equal(compare)) {
					good = true;
					break;
				}
			}
			if(good) {
				res = testLen;
				lo = mid+1;
			}
			else hi = mid-1;
		}
		PrintWriter out = new PrintWriter(System.out);
		if(res == -1) out.println("Just a legend");
		else for(int i = 0; i < res; i++) out.print(s[i]);
		out.flush();
	}


	static class Hash{

		long[] hash = new long[3];
		int len;

		public Hash() {
			this.len = 0;
		}
		
		public Hash copy() {
			Hash res = new Hash();
			res.len = len;
			for(int i = 0; i < 2; i++) res.hash[i] = hash[i];
			return res;
		}
		
		public void add(int p) {
			len++;
			for(int i = 0; i < 2; i++) {
				hash[i] *= 27;
				hash[i] += p;
				hash[i] %= mods[i];
			}
		}
		
		public void removeFirst(int p) {
			len--;
			for(int i = 0; i < 2; i++) {
				hash[i] -= (p*mp[i][len])%mods[i];
				hash[i] += mods[i];
				hash[i] %= mods[i];
			}
		}
		
		public void addFirst(int p) {
			for(int i = 0; i < 2; i++) {
				hash[i] += (p*mp[i][len])%mods[i];
				hash[i] %= mods[i];
			}
			len++;
		}

		public boolean equal(Hash p) {
			for(int i = 0; i < 2; i++) {
				if(hash[i] != p.hash[i]) return false;
			}
			return true;
		}

		public void concat(Hash p) {
			len += p.len;
			for(int i = 0; i < 2; i++) {
				long mult = mp[i][len];
				hash[i] *= mult;
				hash[i] %= mods[i];
				hash[i] += p.hash[i];
				hash[i] %= mods[i];
			}
		}
	}

	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;
 
		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}
 
		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}
 
		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}				
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}
 
		public int nextInt() {
			return (int)nextLong();
		}
 
		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}
 
		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}
 
		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}
 
		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}
 
		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}