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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Set;

public class Oct2D implements Runnable {
	private InputReader in;
	private PrintWriter out;
	private static final int MAX = 100+5;

	public static void main(String[] args) {
		new Oct2D().run();
	}

	public Oct2D() {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}
	
	private boolean KMR(String haystack, String needle) {
		int a = 31, akm1 = 1;
		for (int i = 0; i < needle.length()-1; i++)
			akm1 *= a;
		int nhash = 0;
		int hhash = 0;
		for (int i = 0; i < needle.length(); i++) {
			nhash = nhash*a + (int)needle.charAt(i);
			hhash = hhash*a + (int)haystack.charAt(i);
		}
		for (int j = needle.length(); j < haystack.length(); j++) {
			int i = j-needle.length();
			if (nhash == hhash && haystack.substring(i,j).equals(needle))
				return true;
			hhash -= akm1*haystack.charAt(i);
			hhash = hhash*a + haystack.charAt(j);
		}
		if (nhash == hhash && haystack.endsWith(needle))
			return true;
		return false;
	}
	
	public void run() {
		String line = in.readLine();
		if (line.length() < 3) {
			out.println("Just a legend");
			out.close();
			return;
		}
		String middle = line.substring(1,line.length()-1);
		int n = 0;
		int b = line.length()-1;
	    while (n+1 != b) {
	    	int m = (n+b)/2;
	    	if (KMR(middle,line.substring(0,m)))
	    		n = m;
	    	else b = m;
	    }
	    
	    int thash = line.substring(line.length()-n,line.length()).hashCode();
	    int phash = line.substring(0,n).hashCode();
	    int akm1 = 1;
		for (int i = 0; i < n-1; i++)
			akm1 *= 31;
		int reva = -1108378657;
	    
		while (!(n == 0 || thash == phash && line.endsWith(line.substring(0,n)))) {
			thash -= akm1*line.charAt(line.length()-n);
			akm1 *= reva;
			phash -= line.charAt(n-1);
			phash *= reva;
			n--;
		}
		
	    if (n == 0)
	    	out.println("Just a legend");
	    else
	    	out.println(line.substring(0, n));
	    out.close();
	}
	
	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1000];
		private int curChar, numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\r' && c != '\n' && c != -1) {
				buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
	}
}