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.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class SingleAllocationTrie {
	static int[][] t = new int[28][1 << 10];
	static int p = 1;

	static void add(String s) {
		int pointer = 0;
		for (char c : s.toCharArray())
			pointer = t[c - 'a'][pointer] == 0 ? (t[c - 'a'][pointer] = p++) : t[c - 'a'][pointer];
		t[27][pointer] = 1;
	}

	static int get(String s) {
		int pointer = 0;
		for (char c : s.toCharArray())
			pointer = t[c - 'a'][pointer];
		return pointer;
	}

	static boolean contains(String s) {
		return t[27][get(s)] == 1;
	}

	static int rk(String needle, String haystack) {
		if (haystack.length() < needle.length()) {
			return -1;
		}
		char[] h = haystack.toCharArray();
		long needleHash = 0, haystackHash = 0, pow = 1, BASE = 257;
		for (char c : needle.toCharArray()) {
			pow *= BASE;
			needleHash += c;
			needleHash *= BASE;
		}
		for (char c : haystack.substring(0, needle.length()).toCharArray()) {
			haystackHash += c;
			haystackHash *= BASE;
		}
		if (haystackHash == needleHash && haystack.startsWith(needle)) {
			return 0;
		}
		for (int l = 0, r = needle.length(); r < haystack.length(); l++, r++) {
			haystackHash = haystackHash - pow * h[l] + h[r];
			haystackHash *= BASE;
			if (haystackHash == needleHash && haystack.substring(l + 1).startsWith(needle)) {
				return l + 1;
			}
		}
		return -1;

	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		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);
			}
		}
		int ans = -1;
		int l = 0, r = len.size();
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			int res = rk(s.substring(0, length), s.substring(1, s.length() - 1));
			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");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}