import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class SingleAllocationTrie {
	static int[][] t = new int[28][1 << 10];
	static int p = 1;

	static void add(String s) {
		int pointer = 0;
		for (char c : s.toCharArray())
			pointer = t[c - 'a'][pointer] == 0 ? (t[c - 'a'][pointer] = p++) : t[c - 'a'][pointer];
		t[27][pointer] = 1;
	}

	static int get(String s) {
		int pointer = 0;
		for (char c : s.toCharArray())
			pointer = t[c - 'a'][pointer];
		return pointer;
	}

	static boolean contains(String s) {
		return t[27][get(s)] == 1;
	}

	static int rk(String needle, String haystack) {
		if (haystack.length() < needle.length()) {
			return -1;
		}
		char[] h = haystack.toCharArray();
		long needleHash = 0, haystackHash = 0, pow = 1, BASE = 257;
		for (char c : needle.toCharArray()) {
			pow *= BASE;
			needleHash += c;
			needleHash *= BASE;
		}
		for (char c : haystack.substring(0, needle.length()).toCharArray()) {
			haystackHash += c;
			haystackHash *= BASE;
		}
		if (haystackHash == needleHash && haystack.startsWith(needle)) {
			return 0;
		}
		for (int l = 0, r = needle.length(); r < haystack.length(); l++, r++) {
			haystackHash = haystackHash - pow * h[l] + h[r];
			haystackHash *= BASE;
			if (haystackHash == needleHash && haystack.substring(l + 1).startsWith(needle)) {
				return l + 1;
			}
		}
		return -1;

	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}
		int ans = -1;
		int l = 0, r = len.size();
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			int res = rk(s.substring(0, length), s.substring(1, s.length() - 1));
			if (res == -1) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    private static int[][] dfa;       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        int R = 256;
        // build DFA from pattern
        int m = pat.length();
        dfa = new int[R][m];
        dfa[pat.charAt(0)][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < R; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            KMP(s.substring(0, length));
            int res = search(s.substring(0, length), s.substring(1, s.length() - 1));
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static int[][] dfa = new int[27][1_000_005];       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        for(int[] c : dfa){
            Arrays.fill(c, 0);
        }
        // build DFA from pattern
        int m = pat.length();
        dfa[pat.charAt(0)-'a'][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < 26; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)-'a'][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)-'a'][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)-'a'][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            String str = s.substring(0, length);
//            KMP(str);
//            int res = search(str, middle);
            int res = middle.indexOf(str);
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	private static int[][] dfa = new int[27][1_000_005]; // the KMP automoton

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	public static void KMP(String pat) {
		int m = pat.length();
		dfa[pat.charAt(0) - 'a'][0] = 1;
		for (int x = 0, j = 1; j < m; j++) {
			for (int c = 0; c < 26; c++)
				dfa[c][j] = dfa[c][x]; // Copy mismatch cases.
			dfa[pat.charAt(j) - 'a'][j] = j + 1; // Set match case.
			x = dfa[pat.charAt(j) - 'a'][x]; // Update restart state.
		}
	}

	public static int search(String pat, String txt) {

		// simulate operation of DFA on text
		int m = pat.length();
		int n = txt.length();
		int i, j;
		for (i = 0, j = 0; i < n && j < m; i++) {
			j = dfa[txt.charAt(i) - 'a'][j];
		}
		if (j == m)
			return i - m; // found
		return -1; // not found
	}

	public static void main(String[] args) throws IOException {
		MyScanner in = new MyScanner();
		String s = in.next();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 31;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}
		KMP(s);
		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);

			int res = search(str, middle);
			if (res == -1) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	static class MyScanner {
		byte[] buffer = new byte[16384];
		int ptr = buffer.length;
		byte b = 0;

		byte read() throws IOException {
			if (ptr == buffer.length) {
				ptr = 0;
				System.in.read(buffer);
			}
			return buffer[ptr++];
		}

		int nextInt() throws IOException {
			int sign = 1;
			while (b != '-' && (b < '0' || b > '9')) {
				b = read();
			}
			if (b == '-') {
				b = read();
				sign = -1;
			}
			int num = 0;
			while (b >= '0' && b <= '9') {
				num *= 10;
				num += b - '0';
				b = read();
			}
			return num * sign;
		}

		String next() throws IOException {
			while (b < 33) {
				b = read();
			}
			StringBuilder sb = new StringBuilder();
			while (b >= 33) {
				sb.append((char) b);
				b = read();
			}
			return sb.toString();
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static int[][] dfa = new int[1_000_005][27];       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        for(int[] c : dfa){
            Arrays.fill(c, 0);
        }
        // build DFA from pattern
        int m = pat.length();
        dfa[pat.charAt(0)-'a'][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < 26; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)-'a'][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)-'a'][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)-'a'][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            String str = s.substring(0, length);
            KMP(str);
            int res = search(str, middle);
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	static Map<Character, Integer>[] dfa = new HashMap[1_000_005];

	static {
		for (int i = 0; i < dfa.length; i++) {
			dfa[i] = new HashMap<>();
		}
	}

	static Map<Character, Integer>[] buildDFAsmall(String s) {
		for (int i = 0; i < dfa.length; i++) {
			dfa[i].clear();
		}
		int lps = 0;
		dfa[0].put(s.charAt(0), 1);

		for (int i = 1; i < s.length(); i++) {
			Map<Character, Integer> m = dfa[lps];

			for (char c : m.keySet()) {
				dfa[i].put(c, dfa[lps].get(c));
			}

			dfa[i].put(s.charAt(i), i + 1);
			lps = dfa[lps].getOrDefault(s.charAt(i), 0);
		}
		return dfa;
	}

	static boolean simulateMap(Map<Character, Integer>[] dfa, String s, String pattern) {
		int state = 0;
		for (char c : s.toCharArray()) {
			state = dfa[state].getOrDefault(c, 0);
			if (state == pattern.length()) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}

		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);
			buildDFAsmall(str);
			boolean res = simulateMap(buildDFAsmall(str), middle, str);
			if (!res) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    private static int[][] dfa;       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        int R = 27;
        // build DFA from pattern
        int m = pat.length();
        dfa = new int[R][m];
        dfa[pat.charAt(0)-'a'][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < R; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)-'a'][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)-'a'][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)-'a'][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            KMP(s.substring(0, length));
            int res = search(s.substring(0, length), s.substring(1, s.length() - 1));
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	private static int[][] dfa = new int[27][1_000_005]; // the KMP automoton

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	public static void KMP(String pat) {
		// for(int[] c : dfa){
		// Arrays.fill(c, 0);
		// }
		// build DFA from pattern
		int m = pat.length();
		dfa[pat.charAt(0) - 'a'][0] = 1;
		for (int x = 0, j = 1; j < m; j++) {
			for (int c = 0; c < 26; c++)
				dfa[c][j] = dfa[c][x]; // Copy mismatch cases.
			dfa[pat.charAt(j) - 'a'][j] = j + 1; // Set match case.
			x = dfa[pat.charAt(j) - 'a'][x]; // Update restart state.
		}
	}

	public static int search(String pat, String txt) {

		// simulate operation of DFA on text
		int m = pat.length();
		int n = txt.length();
		int i, j;
		for (i = 0, j = 0; i < n && j < m; i++) {
			j = dfa[txt.charAt(i) - 'a'][j];
		}
		if (j == m)
			return i - m; // found
		return -1; // not found
	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}
		KMP(s);
		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);

			int res = search(str, middle);
			if (res == -1) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    private static int[][] dfa;       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        int R = 27;
        // build DFA from pattern
        int m = pat.length();
        dfa = new int[R][m];
        dfa[pat.charAt(0)-'a'][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < R; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)-'a'][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)-'a'][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)-'a'][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        String middle = s.substring(1, s.length() - 1);
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            String str = s.substring(0, length);
            KMP(str);
            int res = search(str, middle);
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	static Map<Character, Integer>[] buildDFAsmall(String s) {
		 Map<Character, Integer>[] dfa = new HashMap[s.length()];
		for (int i = 0; i < dfa.length; i++) {
			dfa[i] = new HashMap<>();
		}
		int lps = 0;
		dfa[0].put(s.charAt(0), 1);

		for (int i = 1; i < s.length(); i++) {
			Map<Character, Integer> m = dfa[lps];

			for (char c : m.keySet()) {
				dfa[i].put(c, dfa[lps].get(c));
			}

			dfa[i].put(s.charAt(i), i + 1);
			lps = dfa[lps].getOrDefault(s.charAt(i), 0);
		}
		return dfa;
	}

	static boolean simulateMap(Map<Character, Integer>[] dfa, String s) {
		int state = 0;
		for (char c : s.toCharArray()) {
			state = dfa[state].getOrDefault(c, 0);
			if (state == dfa.length) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}

		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);
			buildDFAsmall(str);
			boolean res = simulateMap(buildDFAsmall(str), middle);
			if (!res) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class SingleAllocationTrie {
	static int[][] t = new int[28][1 << 10];
	static int p = 1;

	static void add(String s) {
		int pointer = 0;
		for (char c : s.toCharArray())
			pointer = t[c - 'a'][pointer] == 0 ? (t[c - 'a'][pointer] = p++) : t[c - 'a'][pointer];
		t[27][pointer] = 1;
	}

	static int get(String s) {
		int pointer = 0;
		for (char c : s.toCharArray())
			pointer = t[c - 'a'][pointer];
		return pointer;
	}

	static boolean contains(String s) {
		return t[27][get(s)] == 1;
	}

	static int rk(String needle, String haystack) {
		if (haystack.length() < needle.length()) {
			return -1;
		}
		char[] h = haystack.toCharArray();
		long needleHash = 0, haystackHash = 0, pow = 1, BASE = 257;
		for (char c : needle.toCharArray()) {
			pow *= BASE;
			needleHash += c;
			needleHash *= BASE;
		}
		for (char c : haystack.substring(0, needle.length()).toCharArray()) {
			haystackHash += c;
			haystackHash *= BASE;
		}
		if (haystackHash == needleHash
//				&& haystack.startsWith(needle)
				) {
			return 0;
		}
		for (int l = 0, r = needle.length(); r < haystack.length(); l++, r++) {
			haystackHash = haystackHash - pow * h[l] + h[r];
			haystackHash *= BASE;
			if (haystackHash == needleHash
//					&& haystack.substring(l + 1).startsWith(needle)
					) {
				return l + 1;
			}
		}
		return -1;

	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}
		int ans = -1;
		int l = 0, r = len.size();
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			int res = rk(s.substring(0, length), s.substring(1, s.length() - 1));
			if (res == -1) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    private static int[][] dfa;       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        int R = 27;
        // build DFA from pattern
        int m = pat.length();
        dfa = new int[R][m];
        dfa[pat.charAt(0)-'a'][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < R; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)-'a'][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)-'a'][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)-'a'][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            String str = s.substring(0, length);
            KMP(str);
            int res = search(str, middle);
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static int rk(String needle, String haystack) {
        if (haystack.length() < needle.length()) {
            return -1;
        }
        char[] h = haystack.toCharArray();
        long needleHash = 0, haystackHash = 0, pow = 1, BASE = 257;
        for (char c : needle.toCharArray()) {
            pow *= BASE;
            needleHash += c;
            needleHash *= BASE;
        }
        for (char c : haystack.substring(0, needle.length()).toCharArray()) {
            haystackHash += c;
            haystackHash *= BASE;
        }
        if (haystackHash == needleHash
//				&& haystack.startsWith(needle)
                ) {
            return 0;
        }
        for (int l = 0, r = needle.length(); r < haystack.length(); l++, r++) {
            haystackHash = haystackHash - pow * h[l] + h[r];
            haystackHash *= BASE;
            if (haystackHash == needleHash
//					&& haystack.substring(l + 1).startsWith(needle)
                    ) {
                return l + 1;
            }
        }
        return -1;

    }
    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        int ans = -1;
        for(int i = len.size()-1; i >= 0; i--){
            int length = len.get(i);
//            System.out.print(length);
            String str = s.substring(0, length);
            int res = rk(str, middle);
            if(res == -1) {
                continue;
            }
            else {
                ans = length;
                break;
            }
        }

        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static int rk(String needle, String haystack) {
        if (haystack.length() < needle.length()) {
            return -1;
        }
        char[] h = haystack.toCharArray();
        long needleHash = 0, haystackHash = 0, pow = 1, BASE = 257;
        for (char c : needle.toCharArray()) {
            pow *= BASE;
            needleHash += c;
            needleHash *= BASE;
        }
        for (char c : haystack.substring(0, needle.length()).toCharArray()) {
            haystackHash += c;
            haystackHash *= BASE;
        }
        if (haystackHash == needleHash
//				&& haystack.startsWith(needle)
                ) {
            return 0;
        }
        for (int l = 0, r = needle.length(); r < haystack.length(); l++, r++) {
            haystackHash = haystackHash - pow * h[l] + h[r];
            haystackHash *= BASE;
            if (haystackHash == needleHash
//					&& haystack.substring(l + 1).startsWith(needle)
                    ) {
                return l + 1;
            }
        }
        return -1;

    }
    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();ß
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        int ans = -1;
        int c = 0;
        for(int i = len.size()-1; i >= 0; i--){
            int length = len.get(i);
            c++;
            String str = s.substring(0, length);
            int res = rk(str, middle);
            if(c > 2){
                break;
            }
            if(res == -1) {
                continue;
            }
            else {
                ans = length;
                break;
            }
        }

        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


package strings;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	static Map<Character, Integer>[] buildDFAsmall(String s) {
		 Map<Character, Integer>[] dfa = new HashMap[s.length()];
		for (int i = 0; i < dfa.length; i++) {
			dfa[i] = new HashMap<>();
		}
		int lps = 0;
		dfa[0].put(s.charAt(0), 1);

		for (int i = 1; i < s.length(); i++) {
			Map<Character, Integer> m = dfa[lps];

			for (char c : m.keySet()) {
				dfa[i].put(c, dfa[lps].get(c));
			}

			dfa[i].put(s.charAt(i), i + 1);
			lps = dfa[lps].getOrDefault(s.charAt(i), 0);
		}
		return dfa;
	}

	static boolean simulateMap(Map<Character, Integer>[] dfa, String s) {
		int state = 0;
		for (char c : s.toCharArray()) {
			state = dfa[state].getOrDefault(c, 0);
			if (state == dfa.length) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}

		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);
			buildDFAsmall(str);
			boolean res = simulateMap(buildDFAsmall(str), middle);
			if (!res) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	static Map<Character, Integer>[] dfa = new HashMap[1000];

	static {
		for (int i = 0; i < dfa.length; i++) {
			dfa[i] = new HashMap<>();
		}
	}

	static Map<Character, Integer>[] buildDFAsmall(String s) {
		for (int i = 0; i < dfa.length; i++) {
			dfa[i].clear();
		}
		int lps = 0;
		dfa[0].put(s.charAt(0), 1);

		for (int i = 1; i < s.length(); i++) {
			Map<Character, Integer> m = dfa[lps];

			for (char c : m.keySet()) {
				dfa[i].put(c, dfa[lps].get(c));
			}

			dfa[i].put(s.charAt(i), i + 1);
			lps = dfa[lps].getOrDefault(s.charAt(i), 0);
		}
		return dfa;
	}

	static boolean simulateMap(Map<Character, Integer>[] dfa, String s, String pattern) {
		int state = 0;
		for (char c : s.toCharArray()) {
			state = dfa[state].getOrDefault(c, 0);
			if (state == pattern.length()) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}

		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);
			buildDFAsmall(str);
			boolean res = simulateMap(buildDFAsmall(str), middle, str);
			if (!res) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	private static int[][] dfa = new int[27][1_000_005]; // the KMP automoton

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	public static void KMP(String pat) {
		// for(int[] c : dfa){
		// Arrays.fill(c, 0);
		// }
		// build DFA from pattern
		int m = pat.length();
		dfa[pat.charAt(0) - 'a'][0] = 1;
		for (int x = 0, j = 1; j < m; j++) {
			for (int c = 0; c < 26; c++)
				dfa[c][j] = dfa[c][x]; // Copy mismatch cases.
			dfa[pat.charAt(j) - 'a'][j] = j + 1; // Set match case.
			x = dfa[pat.charAt(j) - 'a'][x]; // Update restart state.
		}
	}

	public static int search(String pat, String txt) {

		// simulate operation of DFA on text
		int m = pat.length();
		int n = txt.length();
		int i, j;
		for (i = 0, j = 0; i < n && j < m; i++) {
			j = dfa[txt.charAt(i) - 'a'][j];
		}
		if (j == m)
			return i - m; // found
		return -1; // not found
	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}

		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);
			KMP(str);
			int res = search(str, middle);
			if (res == -1) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    private static int[][] dfa;       // the KMP automoton

    /**
     * Preprocesses the pattern string.
     *
     * @param pat the pattern string
     */
    public static void KMP(String pat) {
        int R = 27;
        // build DFA from pattern
        int m = pat.length();
        dfa = new int[R][m];
        dfa[pat.charAt(0)-'a'][0] = 1;
        for (int x = 0, j = 1; j < m; j++) {
            for (int c = 0; c < R; c++)
                dfa[c][j] = dfa[c][x];     // Copy mismatch cases.
            dfa[pat.charAt(j)-'a'][j] = j+1;   // Set match case.
            x = dfa[pat.charAt(j)-'a'][x];     // Update restart state.
        }
    }

    public static int search(String pat, String txt) {

        // simulate operation of DFA on text
        int m = pat.length();
        int n = txt.length();
        int i, j;
        for (i = 0, j = 0; i < n && j < m; i++) {
            j = dfa[txt.charAt(i)-'a'][j];
        }
        if (j == m) return i - m;    // found
        return -1;                    // not found
    }

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }

        int ans = -1;
        int l = 0, r = len.size();
        String middle = "";
        if(s.length()-1 >= 0) {
            middle = s.substring(1, s.length() - 1);
        }
        while (l != r) {
            int mid = (l + r) / 2;
            int length = len.get(mid);
            // fixprefixsuffix
            String str = s.substring(0, length);
            KMP(str);
            int res = search(str, middle);
            if (res == -1) {
                r = mid;
            } else {
                ans = length;
                l = mid + 1;
            }
        }
        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static int rk(String needle, String haystack) {
        if (haystack.length() < needle.length()) {
            return -1;
        }
        char[] h = haystack.toCharArray();
        long needleHash = 0, haystackHash = 0, pow = 1, BASE = 257;
        for (char c : needle.toCharArray()) {
            pow *= BASE;
            needleHash += c;
            needleHash *= BASE;
        }
        for (char c : haystack.substring(0, needle.length()).toCharArray()) {
            haystackHash += c;
            haystackHash *= BASE;
        }
        if (haystackHash == needleHash
//				&& haystack.startsWith(needle)
                ) {
            return 0;
        }
        for (int l = 0, r = needle.length(); r < haystack.length(); l++, r++) {
            haystackHash = haystackHash - pow * h[l] + h[r];
            haystackHash *= BASE;
            if (haystackHash == needleHash
//					&& haystack.substring(l + 1).startsWith(needle)
                    ) {
                return l + 1;
            }
        }
        return -1;

    }
    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        int ans = -1;
        int c = 0;
        for(int i = len.size()-1; i >= 0; i--){
            int length = len.get(i);
            c++;
            String str = s.substring(0, length);
            int res = rk(str, middle);
            if(c > 2){
                break;
            }
            if(res == -1) {
                continue;
            }
            else {
                ans = length;
                break;
            }
        }

        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


package strings;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	static Map<Character, Integer>[] dfa = new HashMap[1000];

	static {
		for (int i = 0; i < dfa.length; i++) {
			dfa[i] = new HashMap<>();
		}
	}

	static Map<Character, Integer>[] buildDFAsmall(String s) {
		for (int i = 0; i < dfa.length; i++) {
			dfa[i].clear();
		}
		int lps = 0;
		dfa[0].put(s.charAt(0), 1);

		for (int i = 1; i < s.length(); i++) {
			Map<Character, Integer> m = dfa[lps];

			for (char c : m.keySet()) {
				dfa[i].put(c, dfa[lps].get(c));
			}

			dfa[i].put(s.charAt(i), i + 1);
			lps = dfa[lps].getOrDefault(s.charAt(i), 0);
		}
		return dfa;
	}

	static boolean simulateMap(Map<Character, Integer>[] dfa, String s, String pattern) {
		int state = 0;
		for (char c : s.toCharArray()) {
			state = dfa[state].getOrDefault(c, 0);
			if (state == pattern.length()) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 257;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}

		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);
			buildDFAsmall(str);
			boolean res = simulateMap(buildDFAsmall(str), middle, str);
			if (!res) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        long h1 = 0, h2 = 0, pow = 1;
        int base = 257;
        List<Integer> len = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            h1 += s.charAt(i);
            h1 *= base;
            pow *= base;
            h2 += pow * s.charAt(s.length() - i - 1);
            if (h1 == h2) {
                len.add(i + 1);
            }
        }
        String middle = "";
        if(s.length() > 1) {
            middle = s.substring(1, s.length() - 1);
        }
        int ans = -1;
        for(int i = len.size()-1; i >= 0; i--){
            int length = len.get(i);
//            System.out.print(length);
            String str = s.substring(0, length);
            int res = middle.indexOf(str);
            if(res == -1) {
                continue;
            }
            else {
                ans = length;
                break;
            }
        }

        if (ans != -1) {
            System.out.println(s.substring(0, ans));
        } else {
            System.out.println("Just a legend");
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	private static int[][] dfa = new int[27][1_000_005]; // the KMP automoton

	/**
	 * Preprocesses the pattern string.
	 *
	 * @param pat
	 *            the pattern string
	 */
	public static void KMP(String pat) {
		int m = pat.length();
		dfa[pat.charAt(0) - 'a'][0] = 1;
		for (int x = 0, j = 1; j < m; j++) {
			for (int c = 0; c < 26; c++)
				dfa[c][j] = dfa[c][x]; // Copy mismatch cases.
			dfa[pat.charAt(j) - 'a'][j] = j + 1; // Set match case.
			x = dfa[pat.charAt(j) - 'a'][x]; // Update restart state.
		}
	}

	public static int search(String pat, String txt) {

		// simulate operation of DFA on text
		int m = pat.length();
		int n = txt.length();
		int i, j;
		for (i = 0, j = 0; i < n && j < m; i++) {
			j = dfa[txt.charAt(i) - 'a'][j];
		}
		if (j == m)
			return i - m; // found
		return -1; // not found
	}

	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		long h1 = 0, h2 = 0, pow = 1;
		int base = 31;
		List<Integer> len = new ArrayList<>();
		for (int i = 0; i < s.length() - 1; i++) {
			h1 += s.charAt(i);
			h1 *= base;
			pow *= base;
			h2 += pow * s.charAt(s.length() - i - 1);
			if (h1 == h2) {
				len.add(i + 1);
			}
		}
		KMP(s);
		int ans = -1;
		int l = 0, r = len.size();
		String middle = "";
		if (s.length() > 1) {
			middle = s.substring(1, s.length() - 1);
		}
		while (l != r) {
			int mid = (l + r) / 2;
			int length = len.get(mid);
			// fixprefixsuffix
			String str = s.substring(0, length);

			int res = search(str, middle);
			if (res == -1) {
				r = mid;
			} else {
				ans = length;
				l = mid + 1;
			}
		}
		if (ans != -1) {
			System.out.println(s.substring(0, ans));
		} else {
			System.out.println("Just a legend");
		}
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static StringBuilder sb;

	public static void findAsterix() {
		int n = sb.length();
		StringBuilder fix = new StringBuilder("");
		int i = 0;
		String end = "";
		String soFar = "";
		for (; i < n; i++) {
			char c = sb.charAt(i);
			fix.append(c);
			end = sb.substring(n - 1 - i);
			if (fix.toString().equals(end)) {
				int index = sb.lastIndexOf(end);
				int index2 = sb.indexOf(end, 1);
				if (index != index2 && index2 >= 0) {
					soFar = fix.toString();
				}
				else {
					break;
				}
			}
		}
		if (i == 0) {
			System.out.println("Just a legend");
		} else {
			if (!soFar.equals("")) {
				System.out.println(soFar);
			} else {
				System.out.println("Just a legend");
			}
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder(br.readLine());
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static StringBuilder sb;

	public static void findAsterix() {
		int n = sb.length();
		StringBuilder fix = new StringBuilder("");
		int i = 0;
		String end = "";
		for (; i < n / 2; i++) {
			char c = sb.charAt(i);
			fix.append(c);
			end = sb.substring(n - 1 - i);
			if (fix.toString().equals(end)) {
				break;
			}
		}
		if (i == 0) {
			System.out.println("Just a legend");
		} else {
			sb.delete(n - 1 - i, n);
			sb.delete(0, i + 1);
			int index = sb.indexOf(fix.toString());
			if (index > 0) {
				System.out.println(fix.toString());
			} else {
				System.out.println("Just a legend");
			}
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder(br.readLine());
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static StringBuilder sb;

	public static void findAsterix() {
		int n = sb.length();
		StringBuilder fix = new StringBuilder("");
		int i = 0;
		String end = "";
		int index = -1;
		for (; i < n; i++) {
			char c = sb.charAt(i);
			fix.append(c);
			end = sb.charAt(n - 1 - i) + end;
			if (fix.toString().equals(end)) {
				int index2 = sb.indexOf(end, 1);
				if (n - 1 - i != index2) {
					index = i;
				}
				else {
					break;
				}
			}
		}
		if (i == 0) {
			System.out.println("Just a legend");
		} else {
			if (index != -1) {
				System.out.println(sb.substring(0, index + 1));
			} else {
				System.out.println("Just a legend");
			}
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder(br.readLine());
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	static String sb;

	public static void findAsterix() {
		int n = sb.length();
		char[] s = sb.toCharArray();
		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 && s[R - L] == s[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[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		int index = -1;
		int largest = -1;

		ArrayList<Integer> indexes = new ArrayList<Integer>();
		ArrayList<Integer> values = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (z[i] == 0) {
				continue;
			} else {
				indexes.add(i);
				values.add(z[i]);
			}
		}
		int n2 = indexes.size();
		for (int i = 0; i < n2; i++) {
			int value = values.get(i);
			if (largest >= value) {
				continue;
			}
			for (int j = i + 1; j < n2; j++) {
				int index2 = indexes.get(j);
				int value2 = values.get(j);
				if (value2 == n - index2 && value >= value2 && value2 > largest) {
					index = index2;
					largest = value2;
				}
			}
		}

		if (index == -1) {
			System.out.println("Just a legend");
		} else {
			System.out.println(sb.substring(index, index + largest));
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = br.readLine();
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static StringBuilder sb;

	public static void findAsterix() {
		int n = sb.length();
		StringBuilder fix = new StringBuilder("");
		int i = 0;
		String end = "";
		int tempIndex = -1;
		for (; i < n; i++) {
			char c = sb.charAt(i);
			fix.append(c);
			end = sb.substring(n - 1 - i);
			if (fix.toString().equals(end)) {
				int index2 = sb.indexOf(end, 1);
				if (index2 >= 0 && index2 != n - 1 - i) {
					tempIndex = i;
				}
				else {
					break;
				}
			}
		}
		if (i == 0) {
			System.out.println("Just a legend");
		} else {
			if (tempIndex > 0) {
				System.out.println(sb.substring(0, tempIndex + 1));
			} else {
				System.out.println("Just a legend");
			}
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder(br.readLine());
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	static String sb;

	public static void findAsterix() {
		int n = sb.length();
		char[] s = sb.toCharArray();
		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 && s[R - L] == s[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[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		int index = -1;
		int largest = -1;

		ArrayList<Integer> indexes = new ArrayList<Integer>();
		ArrayList<Integer> values = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (z[i] == 0) {
				continue;
			} else {
				indexes.add(i);
				values.add(z[i]);
			}
		}
		int n2 = indexes.size();
		for (int i = 0; i < n2; i++) {
			int value = values.get(i);
			int k = indexes.size();
			for (int j = i + 1; j < k; j++) {
				int index2 = indexes.get(j);
				int value2 = values.get(j);
				if (value2 == n - index2 && value >= value2 && value2 >= largest) {
					index = i;
					largest = value2;
				}
			}
		}

		if (index == -1) {
			System.out.println("Just a legend");
		} else {
			System.out.println(sb.substring(index, index + largest));
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = br.readLine();
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	static String sb;

	public static void findAsterix() {
		int n = sb.length();
		char[] s = sb.toCharArray();
		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 && s[R - L] == s[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[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		int length = -1;
		int largest = -1;

		// ArrayList<Integer> indexes = new ArrayList<Integer>();
		// //ArrayList<Integer> values = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int x = z[i];
			if (x == 0) {
				continue;
			} else if (largest == -1) {
				largest = x;
			} else if (x <= largest && x == n - i) {
				length = x;
				break;
			}
			else if (largest < x) {
				largest = x;
				length = -1;
			}
		}

		if (length == -1 || largest == -1) {
			System.out.println("Just a legend");
		} else {
			System.out.println(sb.substring(n - length, n));
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = br.readLine();
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	static String sb;

	public static void findAsterix() {
		int n = sb.length();
		char[] s = sb.toCharArray();
		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 && s[R - L] == s[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[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		int index = -1;
		int largest = -1;

		ArrayList<Integer> indexes = new ArrayList<Integer>();
		//ArrayList<Integer> values = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (z[i] == 0) {
				continue;
			} else {
				indexes.add(i);
				//values.add(z[i]);
			}
		}
		int n2 = indexes.size();
		for (int i = 0; i < n2; i++) {
			if (indexes.get(i) < 0) {
				continue;
			}
			int value = z[indexes.get(i)];
			if (largest >= value) {
				continue;
			}
			for (int j = i + 1; j < n2; j++) {
				int index2 = indexes.get(j);
				if (index2 < 0) {
					continue;
				}
				int value2 = z[index2];
				if (value2 == n - index2 && value >= value2 && value2 > largest) {
					index = index2;
					largest = value2;
					indexes.set(j, -1);
				}
			}
		}

		if (index == -1) {
			System.out.println("Just a legend");
		} else {
			System.out.println(sb.substring(index, index + largest));
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = br.readLine();
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static StringBuilder sb;

	public static void findAsterix() {
		int n = sb.length();
		StringBuilder fix = new StringBuilder("");
		int i = 0;
		String end = "";
		int index = -1;
		for (; i < n; i++) {
			char c = sb.charAt(i);
			fix.append(c);
			end = sb.substring(n - 1 - i);
			if (fix.toString().equals(end)) {
				int index2 = sb.indexOf(end, 1);
				if (index2 != n - 1 - i) {
					index = i;
				}
				else {
					break;
				}
			}
		}
		if (i == 0) {
			System.out.println("Just a legend");
		} else {
			if (index > -1) {
				System.out.println(sb.substring(0, index + 1));
			} else {
				System.out.println("Just a legend");
			}
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder(br.readLine());
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static StringBuilder sb;

	public static void findAsterix() {
		int n = sb.length();
		StringBuilder fix = new StringBuilder("");
		int i = 0;
		String end = "";
		String soFar = "";
		for (; i < n; i++) {
			char c = sb.charAt(i);
			fix.append(c);
			end = sb.substring(n - 1 - i);
			if (fix.toString().equals(end) && end.length() != n) {
				StringBuilder sbtemp = new StringBuilder(sb.substring(1));
				int index = sbtemp.lastIndexOf(end);
				int index2 = sbtemp.indexOf(end);
				if (index != index2 && index2 >= 0) {
					soFar = fix.toString();
				}
			}
		}
		if (i == 0) {
			System.out.println("Just a legend");
		} else {
			sb.delete(0, 1);
			int index = sb.lastIndexOf(soFar);
			int index2 = sb.indexOf(soFar);
			if (!soFar.equals("") && index != index2 && index2 >= 0) {
				System.out.println(soFar);
			} else {
				System.out.println("Just a legend");
			}
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder(br.readLine());
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static StringBuilder sb;

	public static void findAsterix() {
		int n = sb.length();
		StringBuilder fix = new StringBuilder("");
		int i = 0;
		String end = "";
		for (; i < n / 2; i++) {
			char c = sb.charAt(i);
			fix.append(c);
			end = sb.substring(n - 1 - i);
			if (fix.toString().equals(end)) {
				break;
			}
		}
		if (i == 0) {
			System.out.println("Just a legend");
		} else {
			sb.delete(n - 1 - i, n);
			sb.delete(0, i + 1);
			int index = sb.indexOf(fix.toString());
			if (index >= 0) {
				System.out.println(fix.toString());
			} else {
				System.out.println("Just a legend");
			}
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder(br.readLine());
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	static String sb;

	public static void findAsterix() {
		int n = sb.length();
		char[] s = sb.toCharArray();
		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 && s[R - L] == s[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[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		int index = -1;
		int largest = -1;

		ArrayList<Integer> indexes = new ArrayList<Integer>();
		//ArrayList<Integer> values = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (z[i] == 0) {
				continue;
			} else {
				indexes.add(i);
				//values.add(z[i]);
			}
		}
		int n2 = indexes.size();
		for (int i = 0; i < n2; i++) {
			int value = z[indexes.get(i)];
			if (largest >= value) {
				continue;
			}
			for (int j = i + 1; j < n2; j++) {
				int index2 = indexes.get(j);
				int value2 = z[index2];
				if (value2 == n - index2 && value >= value2 && value2 > largest) {
					index = index2;
					largest = value2;
				}
			}
		}

		if (index == -1) {
			System.out.println("Just a legend");
		} else {
			System.out.println(sb.substring(index, index + largest));
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = br.readLine();
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	static String sb;

	public static void findAsterix() {
		int n = sb.length();
		char[] s = sb.toCharArray();
		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 && s[R - L] == s[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[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		int index = -1;
		int largest = -1;

		ArrayList<Integer> indexes = new ArrayList<Integer>();
		ArrayList<Integer> values = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (z[i] == 0) {
				continue;
			} else {
				indexes.add(i);
				values.add(z[i]);
			}
		}
		int n2 = indexes.size();
		for (int i = 0; i < n2; i++) {
			int value = values.get(i);
			int k = indexes.size();
			for (int j = i + 1; j < k; j++) {
				int index2 = indexes.get(j);
				int value2 = values.get(j);
				if (value2 == n - index2 && value >= value2 && value2 >= largest) {
					index = index2;
					largest = value2;
				}
			}
		}

		if (index == -1) {
			System.out.println("Just a legend");
		} else {
			System.out.println(sb.substring(index, index + largest));
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = br.readLine();
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	static String sb;

	public static void findAsterix() {
		int n = sb.length();
		char[] s = sb.toCharArray();
		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 && s[R - L] == s[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[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		int index = -1;
		int largest = -1;

		ArrayList<Integer> indexes = new ArrayList<Integer>();
		//ArrayList<Integer> values = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (z[i] == 0) {
				continue;
			} else {
				indexes.add(i);
				//values.add(z[i]);
			}
		}
		int n2 = indexes.size();
		for (int i = 0; i < n2; i++) {
			if (indexes.get(i) < 0) {
				continue;
			}
			int value = z[indexes.get(i)];
			if (largest >= value) {
				continue;
			}
			for (int j = i + 1; j < n2; j++) {
				int index2 = indexes.get(j);
				int value2 = z[index2];
				if (value2 == n - index2 && value >= value2 && value2 > largest) {
					index = index2;
					largest = value2;
					indexes.set(j, -1);
				}
			}
		}

		if (index == -1) {
			System.out.println("Just a legend");
		} else {
			System.out.println(sb.substring(index, index + largest));
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = br.readLine();
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	static String sb;

	public static void findAsterix() {
		int n = sb.length();
		char[] s = sb.toCharArray();
		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 && s[R - L] == s[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[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		int index = -1;
		int largest = -1;

		ArrayList<Integer> indexes = new ArrayList<Integer>();
		ArrayList<Integer> values = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (z[i] == 0) {
				continue;
			} else {
				indexes.add(i);
				values.add(z[i]);
			}
		}
		int n2 = indexes.size();
		for (int i = 0; i < n2; i++) {
			int value = values.get(i);
			if (largest >= value) {
				continue;
			}
			for (int j = i + 1; j < n2; j++) {
				int index2 = indexes.get(j);
				int value2 = values.get(j);
				if (value2 == n - index2 && value >= value2 && value2 >= largest) {
					index = index2;
					largest = value2;
				}
			}
		}

		if (index == -1) {
			System.out.println("Just a legend");
		} else {
			System.out.println(sb.substring(index, index + largest));
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = br.readLine();
		findAsterix();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static StringBuilder sb;

	public static void findAsterix() {
		int n = sb.length();
		StringBuilder fix = new StringBuilder("");
		int i = 0;
		String end = "";
		String soFar = "";
		for (; i < n; i++) {
			char c = sb.charAt(i);
			fix.append(c);
			end = sb.substring(n - 1 - i);
			if (fix.toString().equals(end) && end.length() != n) {
				StringBuilder sbtemp = new StringBuilder(sb.substring(1));
				int index = sbtemp.lastIndexOf(end);
				int index2 = sbtemp.indexOf(end);
				if (index != index2 && index2 >= 0) {
					soFar = fix.toString();
				}
			}
		}
		if (i == 0) {
			System.out.println("Just a legend");
		} else {
			sb.delete(0, 1);
			int index = sb.lastIndexOf(soFar);
			int index2 = sb.indexOf(soFar);
			if (index != index2 && index2 >= 0) {
				System.out.println(soFar);
			} else {
				System.out.println("Just a legend");
			}
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder(br.readLine());
		findAsterix();
	}

}


//package sept;

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

public class TimePass implements Runnable {
    InputStream is;
    PrintWriter out;
    String INPUT = "";
    //boolean debug=false;
    boolean debug=true;
    static long mod=998244353;
    static long mod2=1000000007;

    void solve() throws IOException
	{
	    /*
	    int n=ni();
	    int[] w=na(n);
	    int[] from=new int[2*(n-1)];
	    Pair[] to=new Pair[2*(n-1)];
	    int ind=0;
	    for(int i=0;i<n-1;i++)
	    {
	        int u=ni()-1,v=ni()-1,c=ni();
	        Pair p1=new Pair(v,c);
	        Pair p2=new Pair(u,c);
	        from[ind++]=u;
	        to[ind-1]=p1;
	        from[ind++]=v;
	        to[ind-1]=p2;
	    }
	    Pair[][] g=packU(n,from,to);
	    dp=new long[n];
	    ans=0;
	    comp(0,g,-1,w);
	    out.println(ans);
	    */
	    char[] a=ns().toCharArray();
	    int n=a.length;
	    int[] lps=new int[n];
	    int i=1,len=0;
	    while(i<n)
	    {
	        if(a[i]==a[len])
	        {
	            len++;
	            lps[i]=len;
	            i++;
	        }
	        else
	        {
	            if(len!=0)
	            {
	                len=lps[len-1];
	            }
	            else
	            {
	                lps[i]=0;
	                i++;
	            }
	        }
	    }
	    if(lps[n-1]==0)
	    {
	        out.println("Just a legend");
	        return;
	    }
	    for(i=0;i<n-1;i++)
	    {
	        if(lps[i]==lps[n-1])
	        {
	            for(int j=0;j<lps[n-1];j++)
	            {
	                out.print(a[j]);
	            }
	            out.println();
	            return;
	        }
	    }
	    //out.println(Arrays.toString(lps));
	    if(lps[lps[n-1]-1]==0)
	    {
	        out.println("Just a legend");
	    }
	    else
	    {
	        for(int j=0;j<lps[lps[n-1]-1];j++)
            {
                out.print(a[j]);
            }
            out.println();
	    }

	}

	static long[] dp;
	static long ans;

	static void comp(int u,Pair[][] g,int p,int[] w)
    {
        if(g[u].length==1 && g[u][0].a==p)
        {
            dp[u]=w[u];
            ans=Math.max(ans,dp[u]);
            return;
        }
        long max=0;
        ArrayList<Long> temp=new ArrayList<>();
    	for(Pair pr:g[u])
    	{
    	    int j=pr.a;
    	    if(pr.a!=p)
    	    {
    	        comp(j,g,u,w);
    	        temp.add(dp[j]-pr.b);
    	        max=Math.max(dp[j]+w[u]-pr.b,max);
    	    }
    	}
    	dp[u]=Math.max(w[u],max);
    	if(temp.size()>=2)
    	{
    	    Collections.sort(temp,Collections.reverseOrder());
    	    ans=Math.max(ans,temp.get(0)+temp.get(1)+w[u]);
    	}
    	ans=Math.max(ans,dp[u]);
    }

	static long fnc(int a,int b)
	{
	    return a+(long)1000000007*b;
	}

	static Pair[][] packU(int n,int[] from,Pair[] to)
	{
		Pair[][] g=new Pair[n][];
		int[] p=new int[n];
		for(int f:from)
		{
			p[f]++;
		}
		int m=from.length;
		for(int i=0;i<n;i++)
		{
			g[i]=new Pair[p[i]];
		}
		for(int i=0;i<m;i++)
		{
			g[from[i]][--p[from[i]]]=to[i];
		}
		return g;
	}

	static int[][] packD(int n,int[] from,int[] to)
	{
		int[][] g=new int[n][];
		int[] p=new int[n];
		for(int f:from)
		{
			p[f]++;
		}
		int m=from.length;
		for(int i=0;i<n;i++)
		{
			g[i]=new int[p[i]];
		}
		for(int i=0;i<m;i++)
		{
			g[from[i]][--p[from[i]]]=to[i];
		}
		return g;
	}

    static class Pair
    {
        int a,b,c;
        public Pair(int a,int b
        //,int c
        )
        {
            this.a=a;
            this.b=b;
            //this.c=c;
        }
    }

    static long lcm(int a,int b)
    {
        long val=a;
        val*=b;
        return (val/gcd(a,b));
    }

    static long gcd(long a,long b)
    {
        if(a==0)return b;
        return gcd(b%a,a);
    }

    static int pow(int a, int b, int p)
    {
        long ans = 1, base = a;
        while (b!=0)
        {
            if ((b & 1)!=0)
            {
                ans *= base;
                ans%= p;
            }
            base *= base;
            base%= p;
            b >>= 1;
        }
        return (int)ans;
    }

    static int inv(int x, int p)
    {
        return pow(x, p - 2, p);
    }

    public static long[] radixSort(long[] f){ return radixSort(f, f.length); }
	public static long[] radixSort(long[] f, int n)
	{
		long[] to = new long[n];
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(int)(f[i]&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[(int)(f[i]&0xffff)]++] = f[i];
			long[] d = f; f = to;to = d;
		}
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>16&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>16&0xffff)]++] = f[i];
			long[] d = f; f = to;to = d;
		}
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>32&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>32&0xffff)]++] = f[i];
			long[] d = f; f = to;to = d;
		}
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>48&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>48&0xffff)]++] = f[i];
			long[] d = f; f = to;to = d;
		}
		return f;
	}

    public void run()
    {
        if(debug)oj=true;
        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        try {
			solve();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        out.flush();
        tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception {new Thread(null,new TimePass(),"Main",1<<26).start();}

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}