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.IOException;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.io.BufferedWriter;
import java.util.Locale;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    private static final long MOD = 3168661733l;
    private static final long d = 37;
    private static final long dInv = BigInteger.valueOf(d).modInverse(BigInteger.valueOf(MOD)).longValue();
    private long[] dPow;
    private long[] prefixHash;
    private int n;
    private int[] a;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        char[] _str = in.nextCharArray();
        n = _str.length;
        a = new int[n];
        for (int i = 0; i < n; i++) a[i] = _str[i] - 'a';
        ArrayList<Integer> possibleLength = new ArrayList<Integer>();
        possibleLength.add(0);
        long frontHash = 0;
        long lastHash = 0;
        dPow = new long[n + 1];
        dPow[0] = 1;
        for (int i = 1; i <= n; i++) {
            dPow[i] = (dPow[i - 1] * d) % MOD;
        }
        prefixHash = new long[n - 1];
        for (int i = 0; i < n - 1; i++) {
            frontHash += a[i] * dPow[i];
            lastHash = lastHash * d + a[n - 1 - i];
            frontHash %= MOD;
            lastHash %= MOD;
            if (frontHash == lastHash) possibleLength.add(i + 1);
            prefixHash[i] = frontHash;
        }
        int left = 0, right = possibleLength.size() - 1;
        while (left < right) {
            int mid = (left + right + 1) >> 1;
            if (can(possibleLength.get(mid))) left = mid;
            else right = mid - 1;
        }
        out.println(left > 0 ? String.valueOf(_str).substring(0, possibleLength.get(left)) : "Just a legend");
    }

    private boolean can(int length) {
        if (length == 0) return true;
        long currentHash = prefixHash[length - 1];
        for (int i = length; i < n - 1; i++) {
            currentHash -= a[i - length];
            if (currentHash < 0) currentHash += MOD;
            currentHash = (currentHash * dInv) % MOD;
            currentHash += a[i] * dPow[length - 1];
            currentHash %= MOD;
            if (currentHash == prefixHash[length - 1]) {
                return true;
            }
        }
        return false;
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 20];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public String next() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public char[] nextCharArray() {
        return next().toCharArray();
    }

    }

class OutputWriter {
    private PrintWriter writer;

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

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

    public void println(String x) {
        writer.println(x);
    }

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

    }