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.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class round93B {

    static char[] Text, Pattern;
    static int[] back;
    static int n, m;
    static ArrayList<Integer> occurrences;

    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer st = new StringTokenizer("");

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

    static String next() throws Exception {
        while (true) {
            if (st.hasMoreTokens()) {
                return st.nextToken();
            }
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            st = new StringTokenizer(s);
        }
    }

    public static long[] hash(char[] sequence) {
        long seed = 131;
        long hash_code = sequence[0];
        long[] hash = new long[sequence.length];
        hash[0] = sequence[0];
        for (int i = 1; i < sequence.length; ++i) {
            hash_code = (hash_code * seed) + sequence[i];
            hash[i] = hash_code;
        }
        return hash;
    }

    public static long[] reverseHash(char[] sequence) {
        long seed = 131;
        long hash_code = sequence[0];
        long[] reverse_hash = new long[sequence.length];
        reverse_hash[0] = sequence[0];
        long po = seed;
        for (int i = 1; i < sequence.length; ++i) {
            hash_code = (hash_code + po * sequence[i]);
            reverse_hash[i] = hash_code;
            po = po * seed;
        }
        return reverse_hash;
    }

    public static String reverse(char[] s) {
        StringBuffer ans = new StringBuffer();
        for (int i = s.length - 1; i >= 0; --i)
            ans.append(s[i]);
        return ans.toString();
    }

    // processes the pattern being searched for.
    public static void kmpPreprocess() {
        int i = 0, j = -1;
        back[0] = -1;
        while (i < m) {
            while (j >= 0 && Pattern[i] != Pattern[j])
                j = back[j];
            ++i;
            ++j;
            back[i] = j;
        }
    }

    // does the search
    public static void kmpSearch() {
        int i = 0, j = 0;
        while (i < n) {
            while (j >= 0 && Text[i] != Pattern[j])
                j = back[j];
            ++i;
            ++j;
            if (j == m) {
                occurrences.add(i - j);
                j = back[j];
            }
        }
    }

    public static void main(String[] args) throws Exception {
        char[] s = next().toCharArray();
        long[] hash = hash(s);
        long[] rev_hash = reverseHash((reverse(s).toCharArray()));
        Text = s;
        n = Text.length;
        for (int i = hash.length - 1; i >= 0; --i) {
            if (hash[i] == rev_hash[i] && i != hash.length - 1) {
                Pattern = new char[i + 1];
                for (int j = 0; j <= i; ++j)
                    Pattern[j] = s[j];          
                m = Pattern.length;
                back = new int[m + 1];
                occurrences = new ArrayList<Integer>();
                kmpPreprocess();
                kmpSearch();
                for (int j = 0; j < occurrences.size(); ++j) {
                    int cur = occurrences.get(j);           
                    if (cur != 0 && cur + i < s.length - 1) {
                        System.out.println(new String(Pattern));
                        return;
                    }
                }
            }
        }
        System.out.println("Just a legend");
        return;
    }
}