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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution {

	static InputReader in = new InputReader(System.in);
	static OutputWriter out = new OutputWriter(System.out);
	static int exp = (int) (1e9);
	static int mod = (int) (1e9 + 7);
	static int p = 131;

	private static void getZarr(String str, int[] Z) {
		int n = str.length();
		int L = 0, R = 0;
		for (int i = 1; i < n; ++i) {
			if (i > R) {
				L = R = i;
				while (R < n && str.charAt(R - L) == str.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 < n && str.charAt(R - L) == str.charAt(R))
						R++;

					Z[i] = R - L;
					R--;
				}
			}
		}
	}

	public static void main(String[] args) {

		String str = in.readLine();
		int[] z = new int[str.length()];
		getZarr(str, z);
		int left = -1;
		int right = -1;

		for (int i = 1; i < str.length(); i++) {
			if (i == 1 && z[i] != 0) {
				left = i;
			} else if (i > 1 && z[i] != 0 && z[i] == str.length() - i) {

				if (right == -1) {
					right = i;
				} else if (left == -1) {
					left = right;
					right = i;
				} else {
					left = z[left] > z[right] ? left : right;
					right = i;
				}

			} else {
				if (left == -1) {
					left = i;
				} else {
					left = z[left] > z[i] ? left : i;
				}
			}
			if (right != -1 && left != -1 && z[right] <= z[left]) {
				System.out.println(str.substring(right));
				System.exit(0);
			}
		}

//		System.out.println(Arrays.toString(z));
		System.out.println("Just a legend");

	}

}

class Node {

	int r;
	int idx;

	public Node(int r, int idx) {
		super();
		this.r = r;
		this.idx = idx;
	}

	@Override
	public String toString() {
		return "Node [r=" + r + ", idx=" + idx + "]";
	}

}

class OutputWriter {
	public PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void println(Object... objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}
}

class InputReader {
	private BufferedReader reader;
	private StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());

			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String readLine() {
		try {
			return reader.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public char nextChar() {
		return next().charAt(0);
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public float nextFloat() {
		return Float.parseFloat(next());
	}

}