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 mini(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long maxi(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long mod(long long a) { return a % 1000010; }
long long power(long long a, long long b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return power(a * a, b / 2);
  else
    return a * power(a * a, b / 2);
}
long long powermod(long long a, long long b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return mod(powermod(mod(a * a), b / 2));
  else
    return mod(a) * mod(powermod(mod(a * a), b / 2));
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int prefix_length[1000010];
int cnt[1000010];
void prefix_string(string s) {
  prefix_length[0] = -1;
  int k = -1;
  for (int i = 1; i < s.length(); i++) {
    k = prefix_length[i - 1];
    while (k >= 0 && s[k + 1] != s[i]) {
      k = prefix_length[k];
    }
    if (s[k + 1] == s[i]) k++;
    prefix_length[i] = k;
    if (k > -1) cnt[k]++;
  }
}
int main() {
  string s;
  cin >> s;
  prefix_string(s);
  int k = prefix_length[s.length() - 1];
  if (k > -1 && cnt[k] >= 2) {
    cout << s.substr(0, k + 1) << endl;
    return 0;
  } else {
    if (k == -1 || prefix_length[k] == -1)
      cout << "Just a legend" << endl;
    else
      cout << s.substr(0, prefix_length[k] + 1) << endl;
  }
  return 0;
}