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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Map.Entry;

public class Solution implements Runnable {

	public static void main(String[] args) {
		(new Thread(new Solution())).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String r = in.readLine();
			if (r == null) return null;
			st = new StringTokenizer(r);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	void solve1() throws Exception {
		long t1 = nextInt();
		long t2 = nextInt();
		long x1 = nextInt();
		long x2 = nextInt();
		long t0 = nextInt();
		if (t1 == t0) {
			out.println(x1 + " " + 0);
		} else {
			if (t2 == t0) out.println(0 + " " + x2); else {
				long ay1 = -1, ay2 = -1;
				long tch = -1, tzn = -1;
				long zn = t2 - t0;
				for (long y1 = 0; y1 <= x1; y1++) {
					long ch = (t0 - t1) * y1;
					long y2 = (ch / zn);
					if (ch % zn != 0) y2++;
					if (y2 > x2) continue;
					if (y1 + y2 == 0) continue;
					long qch = ((long)t1 * y1 + (long)t2 * y2);
					long qzn = (y1 + y2);
					if (tch == -1) {
						ay1 = y1; ay2 = y2; tch = qch; tzn = qzn;
					} else {
						if (qch * tzn < tch * qzn || (qch * tzn == tch * qzn && y1 + y2 > ay1 + ay2)) {
							ay1 = y1; ay2 = y2; tch = qch; tzn = qzn;
						}
					}
				}
				out.println(ay1 + " " + ay2);
			}
		}
	}
	
	void solve() throws Exception {
		String s = nextToken();
		int n = s.length();
		int[] pr = new int[n];
		TreeSet<Integer> tm = new TreeSet<Integer>();
		pr[0] = -1;
		tm.add(-1);
		for (int i = 1; i < n; i++) {
			int j = pr[i - 1];
			while (j != -1 && s.charAt(j + 1) != s.charAt(i)) {
				j = pr[j];
			}
			pr[i] = j;
			if (s.charAt(j + 1) == s.charAt(i)) pr[i]++;
			if (i < n - 1) tm.add(pr[i]);
		}
		for (int ans = pr[n - 1]; ans != -1; ans = pr[ans]) {
			if (tm.contains(ans)) {
				out.println(s.substring(0, ans + 1));
				return;
			}
		}
		out.println("Just a legend");
	}

	public void run() {
		Locale.setDefault(Locale.UK);
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
//			in = new BufferedReader(new FileReader("input.txt"));
//			out = new PrintWriter("output.txt");
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.flush();
		}
	}

}