Problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.

Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.

Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened. 

You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

Input

You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

Output

Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

Examples

Input

fixprefixsuffix


Output

fix

Input

abcdabc


Output

Just a legend

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int n, long long int p) {
  long long int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result % p * x % p) % p;
    x = (x % p * x % p) % p;
    n = n / 2;
  }
  return result % p;
}
void solve() {
  string s;
  cin >> s;
  long long int n = s.length();
  vector<long long int> v1(n), p(n, 1);
  for (long long int i = 1; i <= n - 1; i++)
    p[i] = (p[i - 1] * 31) % 1000000007;
  for (long long int i = 0; i <= n - 1; i++)
    v1[i] = (((long long int)s[i] - 'a' + 1) * p[i]) % 1000000007;
  for (long long int i = 1; i <= n - 1; i++)
    v1[i] = (v1[i - 1] + v1[i]) % 1000000007;
  vector<long long int> v2, v3;
  for (long long int i = 0; i <= n - 3; i++) {
    long long int cur = (v1[i] * p[n - 1 - i]) % 1000000007;
    long long int fin = (v1[n - 1] - v1[n - i - 2] + 1000000007) % 1000000007;
    if (cur == fin) {
      v2.push_back(i);
      v3.push_back(v1[i]);
    }
  }
  if (v2.size() == 0) {
    cout << "Just a legend";
    return;
  }
  reverse(v2.begin(), v2.end());
  reverse(v3.begin(), v3.end());
  vector<long long int> v4;
  for (long long int i = 1; i <= n - 1; i++)
    if (s[i] == s[0]) v4.push_back(i);
  for (long long int i = 0; i <= v2.size() - 1; i++) {
    for (long long int j = 0; j <= v4.size() - 1; j++) {
      if (v4[j] + v2[i] < n - 1) {
        long long int a1 =
            (v1[v4[j] + v2[i]] - v1[v4[j] - 1] + 1000000007) % 1000000007;
        long long int a2 = v3[i] * p[v4[j]] % 1000000007;
        if (a1 == a2) {
          for (long long int k = 0; k <= v2[i]; k++) cout << s[k];
          return;
        }
      }
    }
  }
  cout << "Just a legend";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}