/*
 *  Date: 5/9/12
 *   Time: 15:52
 *   Author:
 *      Alexander Marchuk
 *      aamarchuk@gmail.com
 */

//package Password;

import java.io.InputStream;
import java.util.Scanner;

public class Password {

    int N;
    String str;
    char[] s;
    int[] prefixF;
    String inside;

    public boolean readString(InputStream input) {
        Scanner in = new Scanner(input);
        str = in.nextLine();
        s = str.toCharArray();
        N = str.length();
        prefixF = new int[N];
        if(N > 2){
            inside = str.substring(1, N-1);
            return true;
        }else {
            return false;
        }
    }

    public void prefixFunction() {
        if (0 == N)
            return;
        prefixF[0] = 0;
        // System.out.print(prefixF[0]+" ");
        for (int current = 1; current < N; ++current) {
            int matched_prefix = current - 1;
            int candidate = prefixF[matched_prefix];
            while (candidate != 0 && s[current] != s[candidate]) {
                matched_prefix = prefixF[matched_prefix] - 1;
                candidate = prefixF[matched_prefix];
            }

            if (candidate == 0)
                prefixF[current] = s[current] == s[0] ? 1 : 0;
            else
                prefixF[current] = candidate + 1;
            // System.out.print(prefixF[current]+" ");
        }
    }

    public void findAnsw() {

        this.prefixFunction();
        int size = prefixF[N - 1];
        if (size == 0) {
            System.out.println("Just a legend");
        } else {
            while(size > 0){
                String candidate = str.substring(0, size);
                if(inside.contains(candidate)){
                    System.out.println(candidate);
                    return;
                } else {
                    str = candidate;
                    s  = str.toCharArray();
                    N = str.length();
                    this.prefixFunction();
                    size = prefixF[N - 1];
                }
            }
            System.out.println("Just a legend");
        }
    }

    public static void main(String[] args) {
        Password p = new Password();
        if (!p.readString(System.in)){
            System.out.println("Just a legend");
            return;
        }
        p.findAnsw();
    }

}


/*
 *  Date: 5/9/12
 *   Time: 15:52
 *   Author:
 *      Alexander Marchuk
 *      aamarchuk@gmail.com
 */

//package Password;

import java.io.InputStream;
import java.util.Scanner;

public class Password {

    int N;
    String str;
    char[] s;
    int[] prefixF;
    String inside;

    public boolean readString(InputStream input) {
        Scanner in = new Scanner(input);
        str = in.nextLine();
        s = str.toCharArray();
        N = str.length();
        prefixF = new int[N];
        if(N > 2){
            inside = str.substring(1, N-1);
            return true;
        }else {
            return false;
        }
    }

    public void prefixFunction() {
        if (0 == N)
            return;
        prefixF[0] = 0;
        // System.out.print(prefixF[0]+" ");
        for (int current = 1; current < N; ++current) {
            int matched_prefix = current - 1;
            int candidate = prefixF[matched_prefix];
            while (candidate != 0 && s[current] != s[candidate]) {
                matched_prefix = prefixF[matched_prefix] - 1;
                candidate = prefixF[matched_prefix];
            }

            if (candidate == 0)
                prefixF[current] = s[current] == s[0] ? 1 : 0;
            else
                prefixF[current] = candidate + 1;
            // System.out.print(prefixF[current]+" ");
        }
    }

    public void findAnsw() {

        this.prefixFunction();
        int size = prefixF[N - 1];
        if (size == 0) {
            System.out.println("Just a legend");
        } else {
            while(size > 0){
                String candidate = str.substring(0, size);
                if(inside.contains(candidate)){
                    System.out.println(candidate);
                    return;
                } else {
                    size = prefixF[candidate.length()-1];
                }
            }
            System.out.println("Just a legend");
        }
    }

    public static void main(String[] args) {
        Password p = new Password();
        if (!p.readString(System.in)){
            System.out.println("Just a legend");
            return;
        }
        p.findAnsw();
    }

}


/*
 *  Date: 5/9/12
 *   Time: 15:52
 *   Author:
 *      Alexander Marchuk
 *      aamarchuk@gmail.com
 */

//package Password;

import java.io.InputStream;
import java.util.Scanner;

public class Password {

    int N;
    String str;
    char[] s;
    int[] prefixF;
    String inside;

    public boolean readString(InputStream input) {
        Scanner in = new Scanner(input);
        str = in.nextLine();
        s = str.toCharArray();
        N = str.length();
        prefixF = new int[N];
        if(N > 2){
            inside = str.substring(1, N-1);
            return true;
        }else {
            return false;
        }
    }

    public void prefixFunction() {
        if (0 == N)
            return;
        prefixF[0] = 0;
        // System.out.print(prefixF[0]+" ");
        for (int current = 1; current < N; ++current) {
            int matched_prefix = current - 1;
            int candidate = prefixF[matched_prefix];
            while (candidate != 0 && s[current] != s[candidate]) {
                matched_prefix = prefixF[matched_prefix] - 1;
                candidate = prefixF[matched_prefix];
            }

            if (candidate == 0)
                prefixF[current] = s[current] == s[0] ? 1 : 0;
            else
                prefixF[current] = candidate + 1;
            // System.out.print(prefixF[current]+" ");
        }
    }

    public void findAnsw() {

        this.prefixFunction();
        int size = prefixF[N - 1];
        if (size == 0) {
            System.out.println("Just a legend");
        } else {
            while(size > 0){
                String candidate = str.substring(0, size);

                for(int i = size; i < N-1; i++){
                    if(prefixF[i] == size){
                        System.out.println(candidate);
                        return;
                    }
                }
                size = prefixF[candidate.length()-1];
            }
            System.out.println("Just a legend");
        }
    }

    public boolean oneSymblol(String t){
        int i = 0;
        char [] arr = t.toCharArray();
        while(i < t.length()-1 && arr[i] == arr[i+1]){
            i++;
        }
        if(i == t.length()-1){
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        Password p = new Password();
        if (!p.readString(System.in)){
            System.out.println("Just a legend");
            return;
        }
        p.findAnsw();
    }

}


/*
 *  Date: 5/9/12
 *   Time: 15:52
 *   Author:
 *      Alexander Marchuk
 *      aamarchuk@gmail.com
 */

//package Password;

import java.io.InputStream;
import java.util.Scanner;

public class Password {

    int N;
    String str;
    char[] s;
    int[] prefixF;
    String inside;

    public void readString(InputStream input) {
        Scanner in = new Scanner(input);
        str = in.nextLine();
        s = str.toCharArray();
        N = str.length();
        prefixF = new int[N];
        inside = str.substring(1,N-1);
    }

    public void prefixFunction() {
        if (0 == N)
            return;
        prefixF[0] = 0;
        // System.out.print(prefixF[0]+" ");
        for (int current = 1; current < N; ++current) {
            int matched_prefix = current - 1;
            int candidate = prefixF[matched_prefix];
            while (candidate != 0 && s[current] != s[candidate]) {
                matched_prefix = prefixF[matched_prefix] - 1;
                candidate = prefixF[matched_prefix];
            }

            if (candidate == 0)
                prefixF[current] = s[current] == s[0] ? 1 : 0;
            else
                prefixF[current] = candidate + 1;
            // System.out.print(prefixF[current]+" ");
        }
    }

    public void findAnsw() {

        this.prefixFunction();
        int size = prefixF[N - 1];
        if (size == 0) {
            System.out.println("Just a legend");
        } else {
            while(size > 0){
                size = prefixF[N - 1];
                String candidate = str.substring(0, size);
                if(inside.contains(candidate)){
                    System.out.println(candidate);
                    return;
                } else {
                    str = candidate;
                    s  = str.toCharArray();
                    N = str.length();
                    this.prefixFunction();
                }
            }
        }
        System.out.println("Just a legend");
    }

    public static void main(String[] args) {
        Password p = new Password();
        p.readString(System.in);
        p.findAnsw();
    }

}


/*
 *  Date: 5/9/12
 *   Time: 15:52
 *   Author:
 *      Alexander Marchuk
 *      aamarchuk@gmail.com
 */

//package Password;

import java.io.InputStream;
import java.util.Scanner;

public class Password {

    int N;
    String str;
    char[] s;
    int[] prefixF;
    String inside;

    public void readString(InputStream input) {
        Scanner in = new Scanner(input);
        str = in.nextLine();
        s = str.toCharArray();
        N = str.length();
        prefixF = new int[N];
        inside = str.substring(1,N-1);
    }

    public void prefixFunction() {
        if (0 == N)
            return;
        prefixF[0] = 0;
        // System.out.print(prefixF[0]+" ");
        for (int current = 1; current < N; ++current) {
            int matched_prefix = current - 1;
            int candidate = prefixF[matched_prefix];
            while (candidate != 0 && s[current] != s[candidate]) {
                matched_prefix = prefixF[matched_prefix] - 1;
                candidate = prefixF[matched_prefix];
            }

            if (candidate == 0)
                prefixF[current] = s[current] == s[0] ? 1 : 0;
            else
                prefixF[current] = candidate + 1;
            // System.out.print(prefixF[current]+" ");
        }
    }

    public void findAnsw() {

        this.prefixFunction();
        int size = prefixF[N - 1];
        if (size == 0) {
            System.out.println("Just a legend");
        } else {
            while(size > 0){
                String candidate = str.substring(0, size);
                if(inside.contains(candidate)){
                    System.out.println(candidate);
                    return;
                } else {
                    str = candidate;
                    s  = str.toCharArray();
                    N = str.length();
                    this.prefixFunction();
                    size = prefixF[N - 1];
                }
            }
            System.out.println("Just a legend");
        }
    }

    public static void main(String[] args) {
        Password p = new Password();
        p.readString(System.in);
        p.findAnsw();
    }

}


/*
 *  Date: 5/9/12
 *   Time: 15:52
 *   Author:
 *      Alexander Marchuk
 *      aamarchuk@gmail.com
 */

//package Password;

import java.io.InputStream;
import java.util.Scanner;

public class Password {

    int N;
    String str;
    char[] s;
    int[] prefixF;
    String inside;

    public boolean readString(InputStream input) {
        Scanner in = new Scanner(input);
        str = in.nextLine();
        s = str.toCharArray();
        N = str.length();
        prefixF = new int[N];
        if(N > 2){
            inside = str.substring(1, N-1);
            return true;
        }else {
            return false;
        }
    }

    public void prefixFunction() {
        if (0 == N)
            return;
        prefixF[0] = 0;
        // System.out.print(prefixF[0]+" ");
        for (int current = 1; current < N; ++current) {
            int matched_prefix = current - 1;
            int candidate = prefixF[matched_prefix];
            while (candidate != 0 && s[current] != s[candidate]) {
                matched_prefix = prefixF[matched_prefix] - 1;
                candidate = prefixF[matched_prefix];
            }

            if (candidate == 0)
                prefixF[current] = s[current] == s[0] ? 1 : 0;
            else
                prefixF[current] = candidate + 1;
            // System.out.print(prefixF[current]+" ");
        }
    }

    public void findAnsw() {

        this.prefixFunction();
        int size = prefixF[N - 1];
        if (size == 0) {
            System.out.println("Just a legend");
        } else {
            while(size > 0){
                String candidate = str.substring(0, size);
                if(inside.contains(candidate)){
                    System.out.println(candidate);
                    return;
                } else {
                    size = prefixF[candidate.length()-1];
                }
            }
            System.out.println("Just a legend");
        }
    }

    public boolean oneSymblol(String t){
        int i = 0;
        char [] arr = t.toCharArray();
        while(i < t.length()-1 && arr[i] == arr[i+1]){
            i++;
        }
        if(i == t.length()-1){
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        Password p = new Password();
        if (!p.readString(System.in)){
            System.out.println("Just a legend");
            return;
        }
        if(p.oneSymblol(p.str)){
            System.out.println(p.str.substring(0,p.N-2));
        } else{
            p.findAnsw();
        }
    }

}


/*
 *  Date: 5/9/12
 *   Time: 15:52
 *   Author:
 *      Alexander Marchuk
 *      aamarchuk@gmail.com
 */

//package Password;

import java.io.InputStream;
import java.util.Scanner;

public class Password {

    int N;
    String str;
    char[] s;
    int[] prefixF;

    public void readString(InputStream input) {
        Scanner in = new Scanner(input);
        str = in.nextLine();
        s = str.toCharArray();
        N = str.length();
        prefixF = new int[N];
    }

    public void prefixFunction() {
        if (0 == N)
            return;
        prefixF[0] = 0;
        // System.out.print(prefixF[0]+" ");
        for (int current = 1; current < N; ++current) {
            int matched_prefix = current - 1;
            int candidate = prefixF[matched_prefix];
            while (candidate != 0 && s[current] != s[candidate]) {
                matched_prefix = prefixF[matched_prefix] - 1;
                candidate = prefixF[matched_prefix];
            }

            if (candidate == 0)
                prefixF[current] = s[current] == s[0] ? 1 : 0;
            else
                prefixF[current] = candidate + 1;
            // System.out.print(prefixF[current]+" ");
        }
    }

    public void findAnsw() {
        int size = prefixF[N - 1];
        if (size == 0) {
            System.out.println("Just a legend");
        } else {
            String inside = str.substring(1,N-1);
           // System.out.println(inside.contains("fix"));
           // System.out.println(inside);
                String candidate = str.substring(0, size);
          //      System.out.println(candidate);

                if(inside.contains(candidate)){
                    System.out.println(candidate);
                    return;
                } else {
                     System.out.println("Just a legend");
                }
        }
    }

    public static void main(String[] args) {
        Password p = new Password();
        p.readString(System.in);
        p.prefixFunction();
        p.findAnsw();
    }

}


/*
 *  Date: 5/9/12
 *   Time: 15:52
 *   Author:
 *      Alexander Marchuk
 *      aamarchuk@gmail.com
 */

//package Password;

import java.io.InputStream;
import java.util.Scanner;

public class Password {

    int N;
    String str;
    char[] s;
    int[] prefixF;
    String inside;

    public void readString(InputStream input) {
        Scanner in = new Scanner(input);
        str = in.nextLine();
        s = str.toCharArray();
        N = str.length();
        prefixF = new int[N];
        inside = str.substring(1,N-1);
    }

    public void prefixFunction() {
        if (0 == N)
            return;
        prefixF[0] = 0;
        // System.out.print(prefixF[0]+" ");
        for (int current = 1; current < N; ++current) {
            int matched_prefix = current - 1;
            int candidate = prefixF[matched_prefix];
            while (candidate != 0 && s[current] != s[candidate]) {
                matched_prefix = prefixF[matched_prefix] - 1;
                candidate = prefixF[matched_prefix];
            }

            if (candidate == 0)
                prefixF[current] = s[current] == s[0] ? 1 : 0;
            else
                prefixF[current] = candidate + 1;
            // System.out.print(prefixF[current]+" ");
        }
    }

    public void findAnsw() {

        this.prefixFunction();
        int size = prefixF[N - 1];
        if (size == 0) {
            System.out.println("Just a legend");
        } else {
            while(size > 0){
                String candidate = str.substring(0, size);
                if(inside.contains(candidate)){
                    System.out.println(candidate);
                    return;
                } else {
                    str = candidate;
                    s  = str.toCharArray();
                    N = str.length();
                    this.prefixFunction();
                    size = prefixF[N - 1];
                }
            }
        }
        System.out.println("Just a legend");
    }

    public static void main(String[] args) {
        Password p = new Password();
        p.readString(System.in);
        p.findAnsw();
    }

}


/**
 * Created by rearmlkp on 3/11/14.
 */

import java.io.*;
import java.util.*;

public class Practice {
    public static void main(String[] args) throws Exception {
        in.init(System.in);
        String s=in.next();
        int n=s.length(),i;
        KMP res=new KMP(s);
        res.Z_funtion();
        int max=0;
        ArrayList<pair> list=new ArrayList<>();
        for (i=0;i<n;++i) if (res.Z[i]!=0) list.add(new pair(i,res.Z[i]));
        for (i=list.size()-1;i>=0;--i) {
            int vt=list.get(i).vt;
            int gt=list.get(i).gt;
            if (gt<max|((n-vt)==gt)) continue;
            for (int j=i-1;j>=0;--j) {
                int vt2=list.get(j).vt;
                int gt2=list.get(j).gt;
                if (gt2>=gt) {max=gt;break;}
            }
        }
        if (max==0) System.out.println("Just a legend");
        else {
            for (i=0;i<max;++i) System.out.print(s.charAt(i));System.out.println();
        }
    }
}

class pair {
    int vt,gt;
    public pair(int vt,int gt) {this.vt=vt;this.gt=gt;}
}

class KMP { // Substring search using Knuth–Morris–Pratt algorithm (start at 0)
    String S;
    int[] Z,T;
    public KMP(String Wn) {
        S=Wn;
    }
    void KMP_table() {
        T=new int[S.length()];
        int pos=2,cnd=0;
        T[0]=-1;T[1]=0;
        while (pos<S.length()) {
            if (S.charAt(pos-1)==S.charAt(cnd)) {cnd++;T[pos]=cnd;pos++;}
            else {
                if (cnd>0) cnd=T[cnd];
                else {T[pos]=0;pos++;}
            }
        }
    }
    int KMP_search(String W) {
        int m=0,i=0;
        while ((m+i)<S.length()) {
            if (W.charAt(i)==S.charAt(i+m)) {
                if (i==W.length()-1) return m;
                i++;
            }
            else {
                m=m+i-T[i];
                if (T[i]>-1) i=T[i];
                else i=0;
            }
        }
        return -1;
    }
    void Z_funtion() { // Prefix function (start at 0)
        Z=new int[S.length()];
        int L=0,R=0;
        for (int i=1;i<S.length();++i) if (i>R) {
            L=R=i;
            while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
            Z[i]=R-L;R--;
        }
        else {
            int k=i-L;
            if (Z[k]<R-i+1) Z[i]=Z[k];
            else {
                L=i;
                while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
                Z[i]=R-L;R--;
            }
        }
    }
}

class in {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static void init(String input) throws FileNotFoundException {
        reader = new BufferedReader( new FileReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {

            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


/**
 * Created by rearmlkp on 3/11/14.
 */

import java.io.*;
import java.util.*;

public class Practice {
    public static void main(String[] args) throws Exception {
        in.init(System.in);
        String s=in.next();
        int n=s.length(),i;
        KMP res=new KMP(s);
        res.Z_funtion();
        int max=0;
        int[] mMax=new int[n];
        for (i=1;i<n;++i) mMax[i]=Math.max(mMax[i-1],res.Z[i]);
        for (i=n-1;i>=1;--i) if (((n-i)==res.Z[i])&(res.Z[i]<=mMax[i-1])) max=Math.max(max,res.Z[i]);
        if (max==0) System.out.println("Just a legend");
        else {
            StringBuilder sb=new StringBuilder();
            for (i=0;i<max;++i) sb.append(s.charAt(i));System.out.println(sb.toString());
        }
    }
}

class KMP { // Substring search using Knuth–Morris–Pratt algorithm (start at 0)
    String S;
    int[] Z,T;
    public KMP(String Wn) {
        S=Wn;
    }
    void KMP_table() {
        T=new int[S.length()];
        int pos=2,cnd=0;
        T[0]=-1;T[1]=0;
        while (pos<S.length()) {
            if (S.charAt(pos-1)==S.charAt(cnd)) {cnd++;T[pos]=cnd;pos++;}
            else {
                if (cnd>0) cnd=T[cnd];
                else {T[pos]=0;pos++;}
            }
        }
    }
    int KMP_search(String W) {
        int m=0,i=0;
        while ((m+i)<S.length()) {
            if (W.charAt(i)==S.charAt(i+m)) {
                if (i==W.length()-1) return m;
                i++;
            }
            else {
                m=m+i-T[i];
                if (T[i]>-1) i=T[i];
                else i=0;
            }
        }
        return -1;
    }
    void Z_funtion() { // Prefix function (start at 0)
        Z=new int[S.length()];
        int L=0,R=0;
        for (int i=1;i<S.length();++i) if (i>R) {
            L=R=i;
            while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
            Z[i]=R-L;R--;
        }
        else {
            int k=i-L;
            if (Z[k]<R-i+1) Z[i]=Z[k];
            else {
                L=i;
                while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
                Z[i]=R-L;R--;
            }
        }
    }
}

class in {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static void init(String input) throws FileNotFoundException {
        reader = new BufferedReader( new FileReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {

            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


/**
 * Created by rearmlkp on 3/11/14.
 */

import java.io.*;
import java.util.*;

public class Practice {
    public static void main(String[] args) throws Exception {
        in.init(System.in);
        String s=in.next();
        int n=s.length(),i;
        KMP res=new KMP(s);
        res.Z_funtion();
        int max=0;
        ArrayList<pair> list=new ArrayList<>();
        for (i=0;i<n;++i) if (res.Z[i]!=0) list.add(new pair(i,res.Z[i]));
        for (i=list.size()-1;i>=0;--i) {
            int vt=list.get(i).vt;
            int gt=list.get(i).gt;
            if (gt<max) continue;
            for (int j=i-1;j>=0;--j) {
                int vt2=list.get(j).vt;
                int gt2=list.get(j).gt;
                if (gt2>=gt) {max=gt;break;}
            }
        }
        if (max==0) System.out.println("Just a legend");
        else {
            for (i=0;i<max;++i) System.out.print(s.charAt(i));System.out.println();
        }
    }
}

class pair {
    int vt,gt;
    public pair(int vt,int gt) {this.vt=vt;this.gt=gt;}
}

class KMP { // Substring search using Knuth–Morris–Pratt algorithm (start at 0)
    String S;
    int[] Z,T;
    public KMP(String Wn) {
        S=Wn;
    }
    void KMP_table() {
        T=new int[S.length()];
        int pos=2,cnd=0;
        T[0]=-1;T[1]=0;
        while (pos<S.length()) {
            if (S.charAt(pos-1)==S.charAt(cnd)) {cnd++;T[pos]=cnd;pos++;}
            else {
                if (cnd>0) cnd=T[cnd];
                else {T[pos]=0;pos++;}
            }
        }
    }
    int KMP_search(String W) {
        int m=0,i=0;
        while ((m+i)<S.length()) {
            if (W.charAt(i)==S.charAt(i+m)) {
                if (i==W.length()-1) return m;
                i++;
            }
            else {
                m=m+i-T[i];
                if (T[i]>-1) i=T[i];
                else i=0;
            }
        }
        return -1;
    }
    void Z_funtion() { // Prefix function (start at 0)
        Z=new int[S.length()];
        int L=0,R=0;
        for (int i=1;i<S.length();++i) if (i>R) {
            L=R=i;
            while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
            Z[i]=R-L;R--;
        }
        else {
            int k=i-L;
            if (Z[k]<R-i+1) Z[i]=Z[k];
            else {
                L=i;
                while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
                Z[i]=R-L;R--;
            }
        }
    }
}

class in {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static void init(String input) throws FileNotFoundException {
        reader = new BufferedReader( new FileReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {

            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


/**
 * Created by rearmlkp on 3/11/14.
 */

import java.io.*;
import java.util.*;

public class Practice {
    public static void main(String[] args) throws Exception {
        in.init(System.in);
        String s=in.next();
        int n=s.length(),i;
        KMP res=new KMP(s);
        res.Z_funtion();
        int max=0;
        ArrayList<pair> list=new ArrayList<>();
        for (i=0;i<n;++i) if (res.Z[i]!=0) list.add(new pair(i,res.Z[i]));
        for (i=list.size()-1;i>=0;--i) {
            int vt=list.get(i).vt;
            int gt=list.get(i).gt;
            if (gt<max) continue;
            for (int j=i-1;j>=0;--j) {
                int vt2=list.get(j).vt;
                int gt2=list.get(j).gt;
                if (gt2>=gt&(gt+vt2-1)<vt) {max=gt;break;}
            }
        }
        if (max==0) System.out.println("Just a legend");
        else {
            for (i=0;i<max;++i) System.out.print(s.charAt(i));System.out.println();
        }
    }
}

class pair {
    int vt,gt;
    public pair(int vt,int gt) {this.vt=vt;this.gt=gt;}
}

class KMP { // Substring search using Knuth–Morris–Pratt algorithm (start at 0)
    String S;
    int[] Z,T;
    public KMP(String Wn) {
        S=Wn;
    }
    void KMP_table() {
        T=new int[S.length()];
        int pos=2,cnd=0;
        T[0]=-1;T[1]=0;
        while (pos<S.length()) {
            if (S.charAt(pos-1)==S.charAt(cnd)) {cnd++;T[pos]=cnd;pos++;}
            else {
                if (cnd>0) cnd=T[cnd];
                else {T[pos]=0;pos++;}
            }
        }
    }
    int KMP_search(String W) {
        int m=0,i=0;
        while ((m+i)<S.length()) {
            if (W.charAt(i)==S.charAt(i+m)) {
                if (i==W.length()-1) return m;
                i++;
            }
            else {
                m=m+i-T[i];
                if (T[i]>-1) i=T[i];
                else i=0;
            }
        }
        return -1;
    }
    void Z_funtion() { // Prefix function (start at 0)
        Z=new int[S.length()];
        int L=0,R=0;
        for (int i=1;i<S.length();++i) if (i>R) {
            L=R=i;
            while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
            Z[i]=R-L;R--;
        }
        else {
            int k=i-L;
            if (Z[k]<R-i+1) Z[i]=Z[k];
            else {
                L=i;
                while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
                Z[i]=R-L;R--;
            }
        }
    }
}

class in {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static void init(String input) throws FileNotFoundException {
        reader = new BufferedReader( new FileReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {

            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


/**
 * Created by rearmlkp on 3/11/14.
 */

import java.io.*;
import java.util.*;

public class Practice {
    public static void main(String[] args) throws Exception {
        in.init(System.in);
        String s=in.next();
        int n=s.length(),i;
        KMP res=new KMP(s);
        res.Z_funtion();
        int max=0;
        TreeMap<Integer,Integer> map=new TreeMap<>();
        for (i=0;i<n;++i) if (!map.containsKey(res.Z[i])) map.put(res.Z[i],i);
        for (i=n-1;i>=0;--i) if (res.Z[i]==n-i&(map.get(res.Z[i])+(n-i-1))<i) max=Math.max(max,n-i);
        if (max==0) System.out.println("Just a legend");
        else {
            for (i=0;i<max;++i) System.out.print(s.charAt(i));System.out.println();
        }
    }
}

class KMP { // Substring search using Knuth–Morris–Pratt algorithm (start at 0)
    String S;
    int[] Z,T;
    public KMP(String Wn) {
        S=Wn;
    }
    void KMP_table() {
        T=new int[S.length()];
        int pos=2,cnd=0;
        T[0]=-1;T[1]=0;
        while (pos<S.length()) {
            if (S.charAt(pos-1)==S.charAt(cnd)) {cnd++;T[pos]=cnd;pos++;}
            else {
                if (cnd>0) cnd=T[cnd];
                else {T[pos]=0;pos++;}
            }
        }
    }
    int KMP_search(String W) {
        int m=0,i=0;
        while ((m+i)<S.length()) {
            if (W.charAt(i)==S.charAt(i+m)) {
                if (i==W.length()-1) return m;
                i++;
            }
            else {
                m=m+i-T[i];
                if (T[i]>-1) i=T[i];
                else i=0;
            }
        }
        return -1;
    }
    void Z_funtion() { // Prefix function (start at 0)
        Z=new int[S.length()];
        int L=0,R=0;
        for (int i=1;i<S.length();++i) if (i>R) {
            L=R=i;
            while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
            Z[i]=R-L;R--;
        }
        else {
            int k=i-L;
            if (Z[k]<R-i+1) Z[i]=Z[k];
            else {
                L=i;
                while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
                Z[i]=R-L;R--;
            }
        }
    }
}

class in {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static void init(String input) throws FileNotFoundException {
        reader = new BufferedReader( new FileReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {

            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


/**
 * Created by rearmlkp on 3/11/14.
 */

import java.io.*;
import java.util.*;

public class Practice {
    public static void main(String[] args) throws Exception {
        in.init(System.in);
        String s=in.next();
        int n=s.length(),i;
        KMP res=new KMP(s);
        res.Z_funtion();
        int max=0;
        ArrayList<pair> list=new ArrayList<>();
        for (i=0;i<n;++i) if (res.Z[i]!=0) list.add(new pair(i,res.Z[i]));
        for (i=list.size()-1;i>=0;--i) {
            int vt=list.get(i).vt;
            int gt=list.get(i).gt;
            if (gt<max|((n-vt)!=gt)) continue;
            for (int j=i-1;j>=0;--j) {
                int vt2=list.get(j).vt;
                int gt2=list.get(j).gt;
                if (gt2>=gt) {max=gt;break;}
            }
        }
        if (max==0) System.out.println("Just a legend");
        else {
            for (i=0;i<max;++i) System.out.print(s.charAt(i));System.out.println();
        }
    }
}

class pair {
    int vt,gt;
    public pair(int vt,int gt) {this.vt=vt;this.gt=gt;}
}

class KMP { // Substring search using Knuth–Morris–Pratt algorithm (start at 0)
    String S;
    int[] Z,T;
    public KMP(String Wn) {
        S=Wn;
    }
    void KMP_table() {
        T=new int[S.length()];
        int pos=2,cnd=0;
        T[0]=-1;T[1]=0;
        while (pos<S.length()) {
            if (S.charAt(pos-1)==S.charAt(cnd)) {cnd++;T[pos]=cnd;pos++;}
            else {
                if (cnd>0) cnd=T[cnd];
                else {T[pos]=0;pos++;}
            }
        }
    }
    int KMP_search(String W) {
        int m=0,i=0;
        while ((m+i)<S.length()) {
            if (W.charAt(i)==S.charAt(i+m)) {
                if (i==W.length()-1) return m;
                i++;
            }
            else {
                m=m+i-T[i];
                if (T[i]>-1) i=T[i];
                else i=0;
            }
        }
        return -1;
    }
    void Z_funtion() { // Prefix function (start at 0)
        Z=new int[S.length()];
        int L=0,R=0;
        for (int i=1;i<S.length();++i) if (i>R) {
            L=R=i;
            while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
            Z[i]=R-L;R--;
        }
        else {
            int k=i-L;
            if (Z[k]<R-i+1) Z[i]=Z[k];
            else {
                L=i;
                while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
                Z[i]=R-L;R--;
            }
        }
    }
}

class in {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static void init(String input) throws FileNotFoundException {
        reader = new BufferedReader( new FileReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {

            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


/**
 * Created by rearmlkp on 3/11/14.
 */

import java.io.*;
import java.util.*;

public class Practice {
    public static void main(String[] args) throws Exception {
        in.init(System.in);
        String s=in.next();
        int n=s.length(),i;
        KMP res=new KMP(s);
        res.Z_funtion();
        int max=0;
        int[] mMax=new int[n];
        for (i=1;i<n;++i) mMax[i]=Math.max(mMax[i-1],res.Z[i]);
        for (i=n-1;i>=1;--i) if (((n-i)==res.Z[i])&(res.Z[i]<=mMax[i-1])) max=Math.max(max,res.Z[i]);
        if (max==0) System.out.println("Just a legend");
        else {
            for (i=0;i<max;++i) System.out.print(s.charAt(i));System.out.println();
        }
    }
}

class KMP { // Substring search using Knuth–Morris–Pratt algorithm (start at 0)
    String S;
    int[] Z,T;
    public KMP(String Wn) {
        S=Wn;
    }
    void KMP_table() {
        T=new int[S.length()];
        int pos=2,cnd=0;
        T[0]=-1;T[1]=0;
        while (pos<S.length()) {
            if (S.charAt(pos-1)==S.charAt(cnd)) {cnd++;T[pos]=cnd;pos++;}
            else {
                if (cnd>0) cnd=T[cnd];
                else {T[pos]=0;pos++;}
            }
        }
    }
    int KMP_search(String W) {
        int m=0,i=0;
        while ((m+i)<S.length()) {
            if (W.charAt(i)==S.charAt(i+m)) {
                if (i==W.length()-1) return m;
                i++;
            }
            else {
                m=m+i-T[i];
                if (T[i]>-1) i=T[i];
                else i=0;
            }
        }
        return -1;
    }
    void Z_funtion() { // Prefix function (start at 0)
        Z=new int[S.length()];
        int L=0,R=0;
        for (int i=1;i<S.length();++i) if (i>R) {
            L=R=i;
            while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
            Z[i]=R-L;R--;
        }
        else {
            int k=i-L;
            if (Z[k]<R-i+1) Z[i]=Z[k];
            else {
                L=i;
                while (R<S.length()&S.charAt(R-L)==S.charAt(R)) {++R;if (R==S.length()) break;}
                Z[i]=R-L;R--;
            }
        }
    }
}

class in {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static void init(String input) throws FileNotFoundException {
        reader = new BufferedReader( new FileReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {

            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


import java.util.*;
public class Main {
	public static void main(String[] args0){
//		long time = System.currentTimeMillis();
		Scanner scan = new Scanner(System.in);

		char[] l1 = scan.next().toCharArray();
		long time = System.currentTimeMillis();
		int[] fin = new int[l1.length];
		fin[0] = l1.length;
		A:
		for (int ptr = 1;;){
//			px(ptr,fin);
			if (ptr >= l1.length) break;
			for (;;){
				if (ptr >= l1.length || fin[ptr] + ptr >= l1.length){
					break;
				}
				if (l1[fin[ptr]] == l1[fin[ptr] + ptr]){
					fin[ptr]++;
				}
				else break;
			}
			for (int j = ptr + 1; j < ptr + fin[ptr]; j++){
				if (fin[j - ptr] >= ptr + fin[ptr] - j){
					fin[j] = ptr + fin[ptr] - j;
					ptr = j;
					continue A;
				}
				else {
					fin[j] = fin[j - ptr];
				}
			}
			ptr++;
		}
//		px(fin);
//		px((System.currentTimeMillis() - time)*0.0001);
		int val2 = Integer.MIN_VALUE;
		boolean[] ex = new boolean[l1.length + 1];
		for (int i = 1; i < l1.length; i++){
//			px(i, fin[i]);
			if (fin[i] + i == l1.length){
				ex[fin[i]] = true;
				val2 = Math.max(val2, Math.max(fin[i] - 1, 0));
			}
			else {
				val2 = Math.max(val2, fin[i]);
			}
		}
		int ans = 0;
		for (int i = 0;i <= val2;i ++){
			if (ex[i]) ans = i;
		}
		if (ans == 0){
			System.out.println("Just a legend");
		}
		else
		System.out.println(String.valueOf(Arrays.copyOf(l1, ans)));
	}
	static void px(Object ... objects){
		System.out.println(Arrays.deepToString(objects));
	}
}


import java.util.*;
public class Main {
	public static void main(String[] args0){
//		long time = System.currentTimeMillis();
		Scanner scan = new Scanner(System.in);

		char[] l1 = scan.next().toCharArray();
		long time = System.currentTimeMillis();
		int[] fin = new int[l1.length];
		A:
		for (int ptr = 1;;){
//			px(ptr,fin);
			if (ptr >= l1.length) break;
			for (;;){
				if (ptr >= l1.length || fin[ptr] + ptr >= l1.length){
					break;
				}
				if (l1[fin[ptr]] == l1[fin[ptr] + ptr]){
					fin[ptr]++;
				}
				else break;
			}
			for (int j = ptr + 1; j < ptr + fin[ptr]; j++){
				if (fin[j - ptr] >= ptr + fin[ptr] - j){
					fin[j] = ptr + fin[ptr] - j;
					ptr = j;
					continue A;
				}
				else {
					fin[j] = fin[j - ptr];
				}
			}
			ptr++;
		}
//		px(fin);
//		px((System.currentTimeMillis() - time)*0.0001);
		int val2 = Integer.MIN_VALUE;
		int val3 = Integer.MIN_VALUE;
		for (int i = 1; i < l1.length; i++){
			if (fin[i] + i == l1.length){
				val3 = Math.max(val3, fin[i]);
			}
			else {
				val2 = Math.max(val2, fin[i]);
			}
		}
		if (val2 < 0 || val3 < 0
				|| Math.min(val2, val3) == 0
				){
			System.out.println("Just a legend");
		}
		else
		System.out.println(String.valueOf(Arrays.copyOf(l1, Math.min(val2,val3))));
	}
	static void px(Object ... objects){
		System.out.println(Arrays.deepToString(objects));
	}
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		String s = nextToken();
                int N = s.length();
                int[] pi = kmpPrefixFunction(s.toCharArray());

                boolean[] wasInner = new boolean[pi.length];
                for(int i = 0; i < N-1; i++) wasInner[pi[i]] = true; //these are the values which INNER STRING HAVE PREFIX

                int k = pi[N-1];    //take the last character's PI (k), and now find a substring which is also inner substring
                while(k > 0){
                    if(wasInner[k]){
                        System.out.println(s.substring(0, k));
                        return;
                    }
                    k = pi[k-1];
                }

                System.out.println("Just a legend");
	}

        private int[] kmpPrefixFunction(char[] c){
            int N = c.length;
            int[] pi = new int[N];

            pi[0] = 0;
            for(int i = 1; i < N; i++){
                int j = pi[i-1];
                while(j > 0 && c[i] != c[j]) j = pi[j-1];
                if(c[i] == c[j]) ++j;
                pi[i] = j;
            }

            return pi;
        }

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

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

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

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

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		char[] c = nextToken().toCharArray();
                int[] z = zAlgorithm(c);
                int N = c.length;

                int match = 0;
                for(int i = 1; i < N; i++){
                    if(z[i] > 0){
                        if(i != N - z[i] && z[i] == z[N - z[i]]){
                            match = Math.max(match, z[i]);
                        }
                    }
                }

                StringBuilder ans = new StringBuilder();
                for(int i = 0; i < match; i++) ans.append(c[i]);

                if(match == 0)System.out.println("Just a legend");
                else System.out.println(ans.toString());
	}

        private int[] zAlgorithm(char[] c){
            int N = c.length;
            int[] z = new int[N];
            z[0] = 0;
            int left = 0, right = 0;

            for(int i = 1; i < N; i++){
                if( i > right){
                    left = right = i;
                    while(right < N && c[right- left] == c[right]) right++;
                    z[i] = right - left;
                    right--;
                }
                else{
                    int k = i - left;
                    if(z[k] < right - i + 1) z[i] = z[k];
                    else{
                        left = i;
                        while(right < N && c[right - left] == c[right]) right++;
                        z[i] = right- left;
                        right--;
                    }
                }
            }

            return z;
        }

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

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

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

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

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		String s = nextToken();
                int N = s.length();
                int[] pi = kmpPrefixFunction(s.toCharArray());

                boolean[] wasInner = new boolean[pi.length];
                for(int i = 0; i < N-1; i++) wasInner[pi[i]] = true; //these are the values which INNER STRING HAVE PREFIX

                int k = pi[N-1];    //take the last character's PI (k), and now find a substring which is also inner substring
                while(k > 0){
                    if(wasInner[k]){
                        System.out.println(s.substring(0, k));
                        return;
                    }
                    k = pi[k];
                }

                System.out.println("Just a legend");
	}

        private int[] kmpPrefixFunction(char[] c){
            int N = c.length;
            int[] pi = new int[N];

            pi[0] = 0;
            for(int i = 1; i < N; i++){
                int j = pi[i-1];
                while(j > 0 && c[i] != c[j]) j = pi[j];
                if(c[i] == c[j]) ++j;
                pi[i] = j;
            }

            return pi;
        }

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

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

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

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

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		String s = nextToken();
                int N = s.length();
                int[] pi = kmpPrefixFunction(s.toCharArray());

                boolean[] wasInner = new boolean[pi.length];
                for(int i = 0; i < N-1; i++) wasInner[pi[i]] = true; //these are the values which INNER STRING HAVE PREFIX

                print1Int(pi);

                int k = pi[N-1];    //take the last character's PI (k), and now find a substring which is also inner substring
                while(k > 0){
                    if(wasInner[k]){
                        System.out.println(s.substring(0, k));
                        return;
                    }
                    k = pi[k-1];
                }

                System.out.println("Just a legend");
	}

        private int[] kmpPrefixFunction(char[] c){
            int N = c.length;
            int[] pi = new int[N];

            pi[0] = 0;
            for(int i = 1; i < N; i++){
                int j = pi[i-1];
                while(j > 0 && c[i] != c[j]) j = pi[j-1];
                if(c[i] == c[j]) ++j;
                pi[i] = j;
            }

            return pi;
        }

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

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

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

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

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		// using Z-ALGORITHM
            String s = nextToken();
            int[] z = zAlgorithm(s.toCharArray());

            int N = z.length;
            int answer = 0;
            int max = 0; //max stores the middle max prefix  size
            for(int i = 1; i < N; i++){
                if(z[i] == N-i && max >= N-i){ //we have already seen a prefix in middle of max size and z[i] is the end prefix
                    answer = z[i];
                    break;
                }
                max = Math.max(max, z[i]);
            }

            if(answer <= 0)
                System.out.println("Just a legend");
            else
                System.out.println(s.substring(0, answer));
	}

        private int[] zAlgorithm(char[] c){
            int N = c.length;
            int[] z = new int[N];

            z[0] = 0;
            int left = 0, right = 0;

            for(int i = 0; i < N; i++){
                if(i > right){
                    left = right = i;
                    while(right < N && c[right - left] == c[right]) right++;
                    z[i] = right - left;
                    right--;
                }
                else{
                    int K = i - left;
                    if(z[K] < right - i + 1) z[i] = z[K];
                    else{
                        left = i;
                        while(right < N && c[right - left] == c[right]) right++;
                        z[i] = right - left;
                        right--;
                    }
                }
            }

            return z;
        }

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

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

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

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

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;

public class ZAlgorithm {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String BAD = "Just a legend";
        String word = sc.next();
        int[] z = zalg(word);
        int bestSeen = 0, ans = 0;
        for (int i = 1; i < word.length(); i++) {
            if (z[i] == (word.length()-i) && z[i] <= bestSeen) {
                ans = Math.max(ans, z[i]);
            }
            bestSeen = Math.max(bestSeen, z[i]);
        }
        if (ans == 0) System.out.println(BAD);
        else System.out.println(word.substring(0, ans));
    }

    static int[] zalg(String str) {
        int[] z = new int[str.length()];

        int L = 0, R = 0;
        z[0] = 0;
        for (int i = 1; i < str.length(); i++) {
            if (i > R) {
                //just advance
                L=i;
                R=i;
                while (R < str.length() &&
                    str.charAt(R) == str.charAt(R-L)) R++;
                R--; //went 1 past
                z[i] = R-L+1;
            } else {
                if (z[i-L] < (R-i+1)) z[i] = z[i-L];
                else {
                    L=i;
                    //dont change R because it's good so far.
                    while (R < str.length() &&
                        str.charAt(R) == str.charAt(R-L)) R++;
                    R--; // went 1 past
                    z[i] = R-L+1;
                }
            }
        }

        return z;
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class R93qBPassword {

	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    char s[] = br.readLine().toCharArray();
	    int z[] = zFunction(s);
	    int n = s.length;

	    int maxSuffix[] = new int[n];
	    for(int i=0;i<n;i++)
	    	if(z[i] + i == n)
	    		maxSuffix[i] = z[i];

	    for(int i=n-2;i>=0;i--)
	    	maxSuffix[i] = Math.max(maxSuffix[i], maxSuffix[i+1]);

	    int ans = 0;
	    for(int i=1;i<n-1;i++)
	    	ans = Math.max(ans, Math.min(z[i], maxSuffix[i+1]));

	    w.println(ans == 0 ? "Just a legend" : new String(s).substring(0, ans));
	    w.close();
	}

	public static int[] zFunction(char pat[]){
		int n = pat.length;
		int z[] = new int[n];

		int l = 0,r = 0;
		for(int i=1;i<n;i++){
			if(i > r){
				l = r = i;
				while(r < n && pat[r-l] == pat[r]) r++;
				z[i] = r - l;
				r--;
			}
			else{
				int k = i - l;
				if(z[k] < r - i + 1)	z[i] = z[k];
				else{
					l = i;
					while(r < n && pat[r-l] == pat[r]) r++;
					z[i] = r - l;
					r--;
				}
			}
		}

		z[0] = 0;
		return z;
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class R93qBPassword {

	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    char s[] = br.readLine().toCharArray();
	    int z[] = zFunction(s);
	    int n = s.length;

	    int ans = 0;

	    int max[] = new int[n];
	    for(int i=1;i<n;i++)
	    	max[i] = Math.max(max[i-1], z[i]);

	    for(int i=1;i<n;i++)
	    	if(z[i] + i == n && max[i-1] >= z[i])
	    		ans = Math.max(ans, z[i]);

	    w.println(ans == 0 ? "Just a legend" : new String(s).substring(0, ans));
	    w.close();
	}

	public static int[] zFunction(char pat[]){
		int n = pat.length;
		int z[] = new int[n];

		int l = 0,r = 0;
		for(int i=1;i<n;i++){
			if(i > r){
				l = r = i;
				while(r < n && pat[r-l] == pat[r]) r++;
				z[i] = r - l;
				r--;
			}
			else{
				int k = i - l;
				if(z[k] < r - i + 1)	z[i] = z[k];
				else{
					l = i;
					while(r < n && pat[r-l] == pat[r]) r++;
					z[i] = r - l;
					r--;
				}
			}
		}

		z[0] = 0;
		return z;
	}

}


import java.io.*;
import java.util.*;
public final class Main {
    private static int[] genZBoxes(String s) {
        int n = s.length();
        int[] z = new int[n];
        int l = 0, r = 0;
        z[0] = n;
        for (int i = 1; i < n; ++i) {
            if (i > r) {
                l = r = i;
                while (r < n && s.charAt(r - l) == s.charAt(r))
                    ++r;
                z[i] = r - l;
                --r;
            } else {
                int k = i - l;
                if (z[k] < r - i + 1)
                    z[i] = z[k];
                else {
                    l = i;
                    while (r < n && s.charAt(r - l) == s.charAt(r))
                        ++r;
                    z[i] = r - l;
                    --r;
                }

            }
        }
        return z;
    }

    public static void solve(String s) {
        int[] l = genZBoxes(s);
        int[] r = genZBoxes(new StringBuilder(s).reverse().toString());
        int[] x = new int[s.length()];
        for (int i = 1, j = 0; i < s.length(); ++i) {
            while (j + 1 < s.length() && r[i] + i - 1 >= j + 1) {
                ++j;
                x[j] = i;
            }
        }
        int ans = 0;
        int start = 0;
        int end = 0;
        for (int i = 1; i < s.length() - 1; ++i) {
            int xx = s.length() - x[s.length() - i - 1] - 1;
            if (l[i] > 0 && i + l[i] - 1 >= xx) {
                if (xx - i + 1 > ans) {
                    ans = xx - i + 1;
                    start = i;
                    end = xx;
                }
            }
        }
        if (ans == 0) {
            Stream.out.println("Just a legend");
        } else {
            Stream.out.println(s.substring(start, end + 1));
        }
        Stream.out.flush();
    }

    public static void main(String[] args) {
        String s = Stream.in.next();
        Main.solve(s);
    }
}

class Stream {
    static class InputClass {
        static BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in));
        static StringTokenizer tokenizer = new StringTokenizer("");

        public boolean hasNext() {
            try {
                while (!tokenizer.hasMoreTokens()) {
                    String line = reader.readLine();
                    if (line == null) return false; // end of file
                    tokenizer = new StringTokenizer(line);
                }
            } catch (Exception e) {
            }
            return true;
        }

        public String next() {
            String ret = null;
            try {
                ret = hasNext() ? tokenizer.nextToken() : null;
            } catch (Exception e) {
            }
            return ret;
        }

        public String nextLine() {
            String ret = null;
            try {
                ret = reader.readLine();
            } catch (Exception e) {
            }
            return ret;
        }

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

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

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

    public static final InputClass in = new InputClass();

    public static final PrintWriter out = new PrintWriter(
            new OutputStreamWriter(System.out));
}


import java.util.Arrays;
import java.util.Scanner;

public class Zfunction {

	/**
	 * @param args
	 */
	public static 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(r - i + 1, z[i - l]);
            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 static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	String s=sc.next();
    int[]z=Zfunction(s);
	int maxz=0;
	String rslt="";
	for(int i=1;i<z.length;i++){
		if(z[i]==z.length-i&&maxz>=z.length-i){
			rslt=s.substring(i);
			break;
		}
		maxz=Math.max(maxz,z[i]);
	}

    if(!rslt.equals(""))
        System.out.println(rslt);
    else
    	System.out.println("Just a legend");

	}

}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        String S = in.readString();
        int n = S.length();
        int arr[] = new int[n];
        arr[0] = 0;
        for(int i=1;i<n;i++){
            int l = arr[i-1];
            while(l>0&&S.charAt(i)!=S.charAt(l)){
                //System.out.println("here "+i);
                l = arr[l-1];
            }
            if(S.charAt(i)==S.charAt(l)){
                l++;
                arr[i] = l;
            }

        }
    //    for(int x:arr)
      //      System.out.print(x+" ");
        //System.out.println(arr[n-1]);
        if(n<3)
            outt.printLine("Just a legend");
        else if(arr[n-1]==n-1)
            outt.printLine(S.substring(2));
        else{
            int x = arr[n-1];
            boolean f = false;
            while(x>0){
                //System.out.println("x = "+x);
                if(isthere(S.substring(0,x), S.substring(1,n-1))){
                    f = true;
                    break;
                }
                //System.out.println(arr[n-x]);
                Arrays.fill(arr, 0);
                for(int i=n-x+1;i<n;i++){
                    int l = arr[i-1];
                    while(l>0&&S.charAt(i)!=S.charAt(l)){
                        l = arr[l];
                    }
                    if(S.charAt(i)==S.charAt(l)){
                        l++;
                        arr[i] = l;
                    }
                }
                x = arr[n-1];
            }
            if(!f)
                outt.printLine("Just a legend");
            else
                outt.printLine(S.subSequence(0, x));
        }
        outt.close();
    }
    static boolean isthere(String pat,String text){
        int arr[] = LPS(pat);
        int n = text.length();
        int i = 0,j = 0;
        while(i<n){
            while(j>0&&pat.charAt(j)!=text.charAt(i)){
                j = arr[j-1];
            }
            if(pat.charAt(j)==text.charAt(i)){
                i++;
                j++;
            }
            else{
                i++;
            }
            if(j==pat.length())
                return true;

        }
        return false;
    }
    static int[] LPS(String S){
        int n = S.length();
        int arr[] = new int[n];
        for(int i=1;i<n;i++){
            int l = arr[i-1];
            while(l>0&&S.charAt(i)!=S.charAt(l)){

                l = arr[l];
            }
            if(S.charAt(i)==S.charAt(l)){
                l++;
                arr[i] = l;
            }

        }
        return arr;
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    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 int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

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

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

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

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


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        String S = in.readString();
        int n = S.length();
        int arr[] = new int[n];
        arr[0] = 0;
        for(int i=1;i<n;i++){
            int l = arr[i-1];
            while(l>0&&S.charAt(i)!=S.charAt(l)){
                //System.out.println("here "+i);
                l = arr[l-1];
            }
            if(S.charAt(i)==S.charAt(l)){
                l++;
                arr[i] = l;
            }

        }
    //    for(int x:arr)
      //      System.out.print(x+" ");
        //System.out.println(arr[n-1]);
        if(arr[n-1]==n-1)
            outt.printLine(S);
        else{
            int x = arr[n-1];
            boolean f = false;
            while(x>0){
                //System.out.println("x = "+x);
                if(isthere(S.substring(0,x), S.substring(1,n-1))){
                    f = true;
                    break;
                }
                //System.out.println(arr[n-x]);
                Arrays.fill(arr, 0);
                for(int i=n-x+1;i<n;i++){
                    int l = arr[i-1];
                    while(l>0&&S.charAt(i)!=S.charAt(l)){
                        l = arr[l];
                    }
                    if(S.charAt(i)==S.charAt(l)){
                        l++;
                        arr[i] = l;
                    }
                }
                x = arr[n-1];
            }
            if(!f)
                outt.printLine("Just a legend");
            else
                outt.printLine(S.subSequence(0, x));
        }
        outt.close();
    }
    static boolean isthere(String pat,String text){
        int arr[] = LPS(pat);
        int n = text.length();
        int i = 0,j = 0;
        while(i<n){
            while(j>0&&pat.charAt(j)!=text.charAt(i)){
                j = arr[j-1];
            }
            if(pat.charAt(j)==text.charAt(i)){
                i++;
                j++;
            }
            else{
                i++;
            }
            if(j==pat.length())
                return true;

        }
        return false;
    }
    static int[] LPS(String S){
        int n = S.length();
        int arr[] = new int[n];
        for(int i=1;i<n;i++){
            int l = arr[i-1];
            while(l>0&&S.charAt(i)!=S.charAt(l)){

                l = arr[l];
            }
            if(S.charAt(i)==S.charAt(l)){
                l++;
                arr[i] = l;
            }

        }
        return arr;
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    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 int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

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

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

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

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


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        String S = in.readString();
        int n = S.length();
        int arr[] = new int[n];
        arr[0] = 0;
        for(int i=1;i<n;i++){
            int l = arr[i-1];
            while(l>0&&S.charAt(i)!=S.charAt(l)){
                //System.out.println("here "+i);
                l = arr[l-1];
            }
            if(S.charAt(i)==S.charAt(l)){
                l++;
                arr[i] = l;
            }

        }
    //    for(int x:arr)
      //      System.out.print(x+" ");
        //System.out.println(arr[n-1]);
        if(n<3)
            outt.printLine("Just a legend");
        else if(arr[n-1]==n-1)
            outt.printLine(S.substring(2));
        else{
            int x = arr[n-1];
            boolean f = false;
            while(x>0){
                //System.out.println("x = "+x);
                if(isthere(S.substring(0,x), S.substring(1,n-1))){
                    f = true;
                    break;
                }
                //System.out.println(arr[n-x]);
                Arrays.fill(arr, 0);
                for(int i=n-x+1;i<n;i++){
                    int l = arr[i-1];
                    while(l>0&&S.charAt(i)!=S.charAt(l)){
                        l = arr[l-1];
                    }
                    if(S.charAt(i)==S.charAt(l)){
                        l++;
                        arr[i] = l;
                    }
                }
                x = arr[n-1];
            }
            if(!f)
                outt.printLine("Just a legend");
            else
                outt.printLine(S.subSequence(0, x));
        }
        outt.close();
    }
    static boolean isthere(String pat,String text){
        int arr[] = LPS(pat);
        int n = text.length();
        int i = 0,j = 0;
        while(i<n){
            while(j>0&&pat.charAt(j)!=text.charAt(i)){
              //  System.out.println("here");
                j = arr[j-1];
            }
            if(pat.charAt(j)==text.charAt(i)){
                i++;
                j++;
            }
            else{
                i++;
            }
            if(j==pat.length())
                return true;

        }
        return false;
    }
    static int[] LPS(String S){
        int n = S.length();
        int arr[] = new int[n];
        for(int i=1;i<n;i++){
            int l = arr[i-1];
            while(l>0&&S.charAt(i)!=S.charAt(l)){
                //System.out.println("bhai");
                l = arr[l-1];
            }
            if(S.charAt(i)==S.charAt(l)){
                l++;
                arr[i] = l;
            }

        }
        return arr;
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    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 int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

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

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

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

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


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        String S = in.readString();
        int n = S.length();
        int arr[] = new int[n];
        arr[0] = 0;
        for(int i=1;i<n;i++){
            int l = arr[i-1];
            while(l>0&&S.charAt(i)!=S.charAt(l)){

                l = arr[l];
            }
            if(S.charAt(i)==S.charAt(l)){
                l++;
                arr[i] = l;
            }

        }
        if(arr[n-1]==n-1)
            outt.printLine(S);
        else{
            int x = arr[n-1];
            if(x==0)
                outt.printLine("Just a legend" );
            else{
                boolean f = false;
                for(int i=1;i<n-1;i++)
                    if(arr[i]==x){
                        f = true;
                        break;
                    }
                if(f){
                    outt.printLine(S.substring(0, x));
                }
                else
                    outt.printLine("Just a legend" );
            }
        }
        outt.close();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    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 int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

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

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

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

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


#include    <bits/stdc++.h>

using namespace std;

#define     trace1(x)       cout <<#x<<" = "<<x<<endl;
#define     trace2(x,y)     cout <<#x<<" = "<<x<<" | "<<#y<<" = "<<y<<endl;
#define     trace3(x,y,z)   cout <<#x<<" = "<<x<<" | "<<#y<<" = "<<y<<" | "<<#z<<" = "<<z<<endl;

const int MOD = 1e9+7;
const int N = 1e5+5;
const long long inf = 1e18;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    cin >> n >> m;
    if((n <= (m+1)) && ((2 * n + 2) >= m))
    {
        for(int i = 0; i < (n + m); i++)
        {
            if(i%3 == 2)cout << 0;
            else cout << 1;
        }
    }
    else cout << -1;
}


#include    <bits/stdc++.h>

using namespace std;

#define     trace1(x)       cout <<#x<<" = "<<x<<endl;
#define     trace2(x,y)     cout <<#x<<" = "<<x<<" | "<<#y<<" = "<<y<<endl;
#define     trace3(x,y,z)   cout <<#x<<" = "<<x<<" | "<<#y<<" = "<<y<<" | "<<#z<<" = "<<z<<endl;

const int MOD = 1e9+7;
const int N = 1e5+5;
const long long inf = 1e18;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    cin >> n >> m;
    if((n <= (m+1)) && ((2 * n + 2) >= m))
    {
        if(n + 1 == m)
        {
            for(int i = 0; i < (m + n); i++)
            {
                if(i%2)cout<<0; else cout << 1;
            }
        }
        else if(m + 1 == n)
        {
            for(int i = 0; i < (m + n); i++)
            {
                if(i%2)cout<<1; else cout << 0;
            }
        }
        else
        {
            //for(int i = 0; i < (n + m); i++)
            int i = 0;
            while(n || m)
            {
                if(i % 3 == 0)
                {
                    if(m)
                    {
                        cout << 1;
                        m--;
                    }
                }
                else if(i % 3 == 1)
                {
                    if(m)
                    {
                        cout << 1;
                        m--;
                    }
                }
                else
                {
                    if(n)
                    {
                        cout << 0;
                        n--;
                    }
                }
                i++;
            }
        }
    }
    else cout << -1;
}


#include    <bits/stdc++.h>

using namespace std;

#define     trace1(x)       cout <<#x<<" = "<<x<<endl;
#define     trace2(x,y)     cout <<#x<<" = "<<x<<" | "<<#y<<" = "<<y<<endl;
#define     trace3(x,y,z)   cout <<#x<<" = "<<x<<" | "<<#y<<" = "<<y<<" | "<<#z<<" = "<<z<<endl;

const int MOD = 1e9+7;
const int N = 1e5+5;
const long long inf = 1e18;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    cin >> n >> m;
    if((n <= (m+1)) && ((2 * n + 2) >= m))
    {
        int i = 0;
        while(n > 0 || m > 0)
        {
            if(n == m)
            {
                //cout << 10;
                printf("10");
                m--; n--;
            }
            else
            {
                if(m >= 2 && n >= 1)
                {
                    //cout << 110;
                    printf("110");
                    m -= 2;
                    n--;
                }
                else if(m >= 2 && n == 0)
                {
                    //cout << 11;
                    printf("11");
                    m -= 2;
                }
                else
                {
                    printf("1");
                    m--;
                }
            }
        }
        i++;
    }
    else cout << -1;
}


#include    <bits/stdc++.h>

using namespace std;

#define     trace1(x)       cout <<#x<<" = "<<x<<endl;
#define     trace2(x,y)     cout <<#x<<" = "<<x<<" | "<<#y<<" = "<<y<<endl;
#define     trace3(x,y,z)   cout <<#x<<" = "<<x<<" | "<<#y<<" = "<<y<<" | "<<#z<<" = "<<z<<endl;

const int MOD = 1e9+7;
const int N = 1e5+5;
const long long inf = 1e18;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    cin >> n >> m;
    if((n <= (m+1)) && ((2 * n + 2) >= m))
    {
        int i = 0;
        while(n > 0 || m > 0)
        {
            if(n == m)
            {
                cout << 10;
                m--; n--;
            }
            else
            {
                cout << 110;
                m -= 2;n--;
            }
        }
    }
    else cout << -1;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios_base::sync_with_stdio(0);
	int c0,c1;
	cin >> c0 >> c1;
	if(c0 > c1 + 1)
	{
		cout <<"-1\n";
		return 0;
	}
	double r = (c1 / (double)c0);
	if(r > 3.00f)
	{
		cout <<"-1\n";
		return 0;
	}
	else
	{

		string ans = "";
		int r0 = c0,r1 = c1;
		for(int i = 1;i <= c0 + c1;i++)
		{
			if(i % 3 == 0)
			{
				ans += '0',r0--;
				if(r1 == r0)
					break;
			}
			else
				ans += '1',r1--;

		}
		//cout << r0 << " " << r1 << endl;
		if(r1 != r0)
		{
			cout << "-1\n";
			return 0;
		}
		while(r1--)
		{
			ans += "10";
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios_base::sync_with_stdio(0);
	int c0,c1;
	cin >> c0 >> c1;
	if(c0 > c1 + 1)
	{
		cout <<"-1\n";
		return 0;
	}
	double r = (c1 / (double)c0);
	if(r > 3.00f)
	{
		cout <<"-1\n";
		return 0;
	}
	else
	{

		string ans = "";
		int r0 = c0,r1 = c1;
		for(int i = 1;i <= c0 + c1;i++)
		{
			if(i % 3 == 0)
			{
				ans += '0',r0--;
				if(r1 == r0)
					break;
			}
			else
				ans += '1',r1--;

		}

		while(r1--)
		{
			ans += "10";
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios_base::sync_with_stdio(0);
	int c0,c1;
	cin >> c0 >> c1;
	if(c0 > c1 + 1)
	{
		cout <<"-1\n";
		return 0;
	}
	double r = (c1 / (double)c0);
	if(r > 3.00f)
	{
		cout <<"-1\n";
		return 0;
	}
	else
	{

		string ans = "";
		int r0 = c0,r1 = c1,last = 0;
		for(int i = 1;i <= c0 + c1;i++)
		{
			if(r1 == r0)
			{
				if(i % 3 == 1)
					last = 0;
				else if(i % 3 == 2)
					last = 1;
				else
					last = 1;
				break;
			}
			if(i % 3 == 0)
			{
				ans += '0',r0--;
			}
			else
				ans += '1',r1--;

		}
//		cout << r0 << " " << r1 << endl;
		if(r1 != r0)
		{
			cout << "-1\n";
			return 0;
		}
		while(r1--)
		{
			if(last == 0)
				ans += "10";
			else
				ans += "01";
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios_base::sync_with_stdio(0);
	int c0,c1;
	cin >> c0 >> c1;
	if(c0 == c1 + 1)
	{
		string ans = "0";
		int last = 0;
		while(c1--)
		{
			if(last == 0)
				ans += "10";
			else
				ans += "01";
		}
		cout << ans << endl;
		return 0;
	}
	if(c0 > c1 + 1)
	{
		cout <<"-1\n";
		return 0;
	}
	double r = (c1 / (double)c0);
	if(r > 3.00f)
	{
		cout <<"-1\n";
		return 0;
	}
	else
	{

		string ans = "";
		int r0 = c0,r1 = c1,last = 0;
		for(int i = 1;i <= c0 + c1;i++)
		{
			if(r1 == r0)
			{
				if(i % 3 == 1)
					last = 0;
				else if(i % 3 == 2)
					last = 1;
				else
					last = 1;
				break;
			}
			if(i % 3 == 0)
			{
				ans += '0',r0--;
			}
			else
				ans += '1',r1--;

		}
//		cout << r0 << " " << r1 << endl;
		if(r1 != r0)
		{
			cout << "-1\n";
			return 0;
		}
		while(r1--)
		{
			if(last == 0)
				ans += "10";
			else
				ans += "01";
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios_base::sync_with_stdio(0);
	int c0,c1;
	cin >> c0 >> c1;
	if(c0 > c1 + 1)
	{
		cout <<"-1\n";
		return 0;
	}
	double r = (c1 / c0);
	if(r > 3.00f)
	{
		cout <<"-1\n";
		return 0;
	}
	else
	{
		string ans = "";
		for(int i = 1;i <= c0 + c1;i++)
		{
			if(i % 3 == 0)
				ans += '0';
			else
				ans += '1';
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios_base::sync_with_stdio(0);
	int c0,c1;
	cin >> c0 >> c1;
	if(c0 > c1 + 1)
	{
		cout <<"-1\n";
		return 0;
	}
	double r = (c1 / (double)c0);
	if(r > 3.00f)
	{
		cout <<"-1\n";
		return 0;
	}
	else
	{

		string ans = "";
		int r0 = 0,r1 = 0;
		for(int i = 1;i <= c0 + c1;i++)
		{
			if(i % 3 == 0)
				ans += '0',r0++;
			else
				ans += '1',r1++;
		}
		if(r0 == c0 && r1 == c1)
			cout << ans << endl;
		else
		{
			r0 = r1 = 0;
			ans = "";
			for(int i = 0;i < c0 + c1;i++)
			{
				if(i % 3 == 0)
					ans += '0',r0++;
				else
					ans += '1',r1++;
			}
			if(r0 == c0 && r1 == c1)
				cout << ans << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios_base::sync_with_stdio(0);
	int c0,c1;
	cin >> c0 >> c1;
	if(c0 == c1 + 1)
	{
		string ans = "0";
		int last = 0;
		while(c1--)
		{
			if(last == 0)
				ans += "10";
			else
				ans += "01";
		}
		cout << ans << endl;
		return 0;
	}
	if(c0 > c1 + 1)
	{
		cout <<"-1\n";
		return 0;
	}
	double r = (c1 / (double)c0);
	if(0)
	{
		;
	}
	else
	{

		string ans = "";
		int r0 = c0,r1 = c1,last = 0;
		for(int i = 1;i <= c0 + c1;i++)
		{
			if(r1 == r0)
			{
				if(i % 3 == 1)
					last = 0;
				else if(i % 3 == 2)
					last = 1;
				else
					last = 1;
				break;
			}
			if(i % 3 == 0)
			{
				ans += '0',r0--;
			}
			else
				ans += '1',r1--;

		}
//		cout << r0 << " " << r1 << endl;
		if(r1 != r0)
		{
			cout << "-1\n";
			return 0;
		}
		while(r1--)
		{
			if(last == 0)
				ans += "10";
			else
				ans += "01";
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios_base::sync_with_stdio(0);
	int c0,c1;
	cin >> c0 >> c1;
	if(c0 > c1 + 1)
	{
		cout <<"-1\n";
		return 0;
	}
	double r = (c1 / c0);
	if(r > 3.00f)
	{
		cout <<"-1\n";
		return 0;
	}
	else
	{
		string ans = "";
		int r0 = 0,r1 = 0;
		for(int i = 1;i <= c0 + c1;i++)
		{
			if(i % 3 == 0)
				ans += '0',r0++;
			else
				ans += '1',r1++;
		}
		if(r0 == c0 && r1 == c1)
			cout << ans << endl;
		else
		{
			r0 = r1 = 0;
			ans = "";
			for(int i = 0;i < c0 + c1;i++)
			{
				if(i % 3 == 0)
					ans += '0',r0++;
				else
					ans += '1',r1++;
			}
			if(r0 == c0 && r1 == c1)
				cout << ans << endl;
		}
	}
	return 0;
}


#include<iostream>

using namespace std;

int main() {
	double n, m;
	cin >> m >> n;
	if (!((n - 2.0 )/ m <= 2.0)) {
		cout << -1;
	}
	else {
		while (n != m) {
			n -= 2;
			m--;
			cout << 110;
		}
		for (int i = 0; i < n; i++) {
			cout << 10;
		}
	}
}


#include<iostream>

using namespace std;

int main() {
	double n, m;
	cin >> m >> n;
	if (!((n - 2.0 )/ m <= 2.0)) {
		cout << -1;
	}
	else {
		while (n != m && n>0 && m > 0) {
			n -= 2;
			m--;
			cout << 110;
		}
		if (m == 0) {
			for (int i = 0; i < n; i++) {
				cout << 1;
			}
		}
		else if (n == 0) {
			for (int i = 0; i < n; i++) {
				cout << 0;
			}
		}
		else {
			for (int i = 0; i < n; i++) {
				cout << 10;
			}
		}
	}
}


#include<iostream>

using namespace std;

int main() {
	double n, m;
	cin >> m >> n;
	if (!((n - 2.0 )/ m <= 2.0)) {
		cout << -1;
	}
	else {
		while (n != m && n>2 && m > 1) {
			n -= 2;
			m--;
			cout << 110;
		}
		if (m == 0) {
			for (int i = 0; i < n; i++) {
				cout << 1;
			}
		}
		else if (n == 0) {
			for (int i = 0; i < n; i++) {
				cout << 0;
			}
		}
		else {
			for (int i = 0; i < n; i++) {
				cout << 10;
			}
		}
	}
}


#include<iostream>

using namespace std;

int main() {
	double n, m;
	cin >> m >> n;
	if (!((n - 2.0 )/ m <= 2.0)) {
		cout << -1;
	}
	else {
		while ((n > 0) || (m > 0)) {
			if (n > 0) {
				cout << 1;
				n--;
			}
			if (n > 0) {
				cout << 1;
				n--;
			}
			if (m > 0) {
				cout << 0;
				m--;
			}
		}
	}
}


#include<iostream>

using namespace std;

int main() {
	double n, m;
	cin >> m >> n;
	if (!((n - 2.0 )/ m <= 2.0)) {
		cout << -1;
	}
	else {
		while (n != m && n>0 && m > 0 && n > m) {
			n -= 2;
			m--;
			cout << 110;
		}
		if (m == 0) {
			for (int i = 0; i < n; i++) {
				cout << 1;
			}
		}
		else if (n == 0) {
			for (int i = 0; i < n; i++) {
				cout << 0;
			}
		}
		else {
			for (int i = 0; i < n; i++) {
				cout << 10;
			}
		}
	}
}


#include<iostream>

using namespace std;

int main() {
	double n, m;
	cin >> m >> n;
	if (!((n - 2.0 )/ m <= 2.0)) {
		cout << -1;
	}
	else {
		while (n != m && n>0 && m > 0 && n > m) {
			n -= 2;
			m--;
			cout << 110;
		}
		if (n > m) {
			cout << 0;
			m--;
		}
		if (m == 0) {
			for (int i = 0; i < n; i++) {
				cout << 1;
			}
		}
		else if (n == 0) {
			for (int i = 0; i < n; i++) {
				cout << 0;
			}
		}
		else {
			for (int i = 0; i < n; i++) {
				cout << 10;
			}
		}
	}
}