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.*;

public class Main {
	private static int[][] dfa = new int[27][1_000_005]; // the KMP automoton

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	public static void KMP(String pat) {
		int m = pat.length();
		dfa[pat.charAt(0) - 'a'][0] = 1;
		for (int x = 0, j = 1; j < m; j++) {
			for (int c = 0; c < 26; c++)
				dfa[c][j] = dfa[c][x]; // Copy mismatch cases.
			dfa[pat.charAt(j) - 'a'][j] = j + 1; // Set match case.
			x = dfa[pat.charAt(j) - 'a'][x]; // Update restart state.
		}
	}

	public static int search(String pat, String txt) {

		// simulate operation of DFA on text
		int m = pat.length();
		int n = txt.length();
		int i, j;
		for (i = 0, j = 0; i < n && j < m; i++) {
			j = dfa[txt.charAt(i) - 'a'][j];
		}
		if (j == m)
			return i - m; // found
		return -1; // not found
	}

	public static void main(String[] args) throws IOException {
		MyScanner in = new MyScanner();
		String s = in.next();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 31;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}
		KMP(s);
		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);

			int res = search(str, middle);
			if (res == -1) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	static class MyScanner {
		byte[] buffer = new byte[16384];
		int ptr = buffer.length;
		byte b = 0;

		byte read() throws IOException {
			if (ptr == buffer.length) {
				ptr = 0;
				System.in.read(buffer);
			}
			return buffer[ptr++];
		}

		int nextInt() throws IOException {
			int sign = 1;
			while (b != '-' && (b < '0' || b > '9')) {
				b = read();
			}
			if (b == '-') {
				b = read();
				sign = -1;
			}
			int num = 0;
			while (b >= '0' && b <= '9') {
				num *= 10;
				num += b - '0';
				b = read();
			}
			return num * sign;
		}

		String next() throws IOException {
			while (b < 33) {
				b = read();
			}
			StringBuilder sb = new StringBuilder();
			while (b >= 33) {
				sb.append((char) b);
				b = read();
			}
			return sb.toString();
		}
	}

}