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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Objects;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        BPassword solver = new BPassword();
        solver.solve(1, in, out);
        out.close();
    }

    static class BPassword {
        private int[] zFunction(String s) {
            int[] z = new int[s.length()];
            for (int i = 1, l = 0, r = 0; i < s.length(); i++) {
                if (i <= r) z[i] = Math.min(z[i - l], r - i + 1);
                while (i + z[i] < s.length() && s.charAt(z[i]) == s.charAt(i + z[i])) ++z[i];
                if (i + z[i] - 1 > r) {
                    l = i;
                    r = i + z[i] - 1;
                }
            }
            return z;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            String str = in.nextLine();
            if (str.length() <= 2) {
                out.println("Just a legend");
                out.flush();
                return;
            }
            int[] z = zFunction(str);
//        out.println(Arrays.toString(z));
            int min = Integer.MAX_VALUE;
            ArrayList<Util.Pair<Integer>> btw = new ArrayList<>();
            ArrayList<Util.Pair<Integer>> end = new ArrayList<>();
            for (int i = 1; i < z.length; i++) {
                if (z[i] + i == z.length) end.add(new Util.Pair<>(z[i], i));
                else if (z[i] != 0) btw.add(new Util.Pair<>(z[i], i));
            }

            Collections.sort(btw, (o1, o2) -> o2.x - o1.x);
            Collections.sort(end, (o1, o2) -> o2.x - o1.x);

            int b1 = -1, e1 = -1, b1_ind = -1;
            if (end.size() == 0) {
                out.println("Just a legend");
                out.flush();
                return;
            }
            if (end.size() > 1) e1 = end.get(1).x;

            if (btw.size() > 0) {
                for (int i = 0; i < end.size(); i++) {
                    if (btw.get(0).x >= end.get(i).x) {
                        b1 = end.get(i).x;
                        b1_ind = end.get(i).y;
                        break;
                    }
                }
            }
//        out.println(btw.toString());
//        out.println(end.toString());
            if (b1 == -1 && e1 == -1) {
                out.println("Just a legend");
                out.flush();
                return;
            }
            if (b1 == -1 && e1 != -1) out.println(str.substring(end.get(1).y, end.get(1).y + e1));
            else if (e1 == -1 && b1 != -1) out.println(str.substring(b1_ind, b1_ind + b1));
            else if (b1 >= e1) out.println(str.substring(b1_ind, b1_ind + b1));
            else out.println(str.substring(end.get(1).y, end.get(1).y + e1));
            out.flush();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

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

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        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 nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

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

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;
        private ArrayList<String> res = new ArrayList<>();
        private StringBuilder sb = new StringBuilder("");

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

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

        public void println(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                sb.append(objects[i]);
            }
            res.add(sb.toString());
            sb = new StringBuilder("");
        }

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

        public void flush() {
            for (String str : res) writer.printf("%s\n", str);
            res.clear();
            sb = new StringBuilder("");
        }

    }

    static class Util {
        public static class Pair<T> {
            public T x;
            public T y;

            public Pair(T x, T y) {
                this.x = x;
                this.y = y;
            }

            public boolean equals(Object obj) {
                if (obj == this) return true;
                if (!(obj instanceof Util.Pair)) return false;
                Util.Pair<T> pair = (Util.Pair<T>) obj;
                return this.x == pair.x && this.y == pair.y;
            }

            public String toString() {
                return ("(" + this.x + "," + this.y + ")");
            }

            public int hashCode() {
                return Objects.hash(x, y);
            }

        }

    }
}