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;
class Double_Hash {
 private:
  string s;
  long long n;
  vector<long long> Hash1;
  vector<long long> power1;
  const long long m1 = 1e9 + 9;
  const long long p1 = 31;
  vector<long long> Hash2;
  vector<long long> power2;
  const long long m2 = 1e9 + 9;
  const long long p2 = 51;

 public:
  pair<long long, long long> FindSubString(long long i, long long j) {
    if (i == 0)
      return {(Hash1[j] * power1[n - 1 - i]) % m1,
              (Hash2[j] * power2[n - 1 - i]) % m2};
    else
      return {((Hash1[j] - Hash1[i - 1] + m1) * power1[n - 1 - i]) % m1,
              ((Hash2[j] - Hash2[i - 1] + m2) * power2[n - 1 - i]) % m2};
  }
  Double_Hash(string &ss) {
    s = ss;
    n = (long long)s.size();
    Hash1.resize(n + 1);
    power1.resize(n + 1);
    Hash2.resize(n + 1);
    power2.resize(n + 1);
    power1[0] = power2[0] = 1;
    for (long long i = 1; i <= n - 1; i++) {
      power1[i] = (power1[i - 1] * p1) % m1;
      power2[i] = (power2[i - 1] * p2) % m2;
    }
    long long sum1 = 0;
    long long sum2 = 0;
    for (long long i = 0; i <= n - 1; i++) {
      sum1 = (sum1 + (s[i] * power1[i]) % m1) % m1;
      Hash1[i] = sum1;
      sum2 = (sum2 + (s[i] * power2[i]) % m2) % m2;
      Hash2[i] = sum2;
    }
  }
};
class Single_Hash {
 private:
  vector<long long> Hash;
  vector<long long> power;
  string s;
  long long n;
  const long long p = 31;
  const long long m = 1e9 + 9;

 public:
  long long FindSubString(long long i, long long j) {
    if (i == 0)
      return (Hash[j] * power[n - 1 - i]) % m;
    else
      return ((Hash[j] - Hash[i - 1] + m) * power[n - 1 - i]) % m;
  }
  Single_Hash(string ss) {
    n = (long long)ss.size();
    s = ss;
    Hash.resize(n + 1);
    power.resize(n + 1);
    power[0] = 1;
    for (long long i = 1; i <= n - 1; i++) power[i] = (power[i - 1] * p) % m;
    long long sum = 0;
    for (long long i = 0; i <= n - 1; i++) {
      sum = (sum + (s[i] * power[i]) % m) % m;
      Hash[i] = sum;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  Double_Hash t(s);
  long long n = (long long)s.size();
  for (long long l = n - 2; l >= 1; l--) {
    pair<long long, long long> fi = t.FindSubString(0, l - 1);
    pair<long long, long long> se = t.FindSubString(n - l, n - 1);
    if (fi == se) {
      for (long long i = 1; i <= n - l - 1; i++) {
        pair<long long, long long> th = t.FindSubString(i, i + l - 1);
        if (fi == th) {
          cout << s.substr(i, l);
          return 0;
        }
      }
    }
  }
  cout << "Just a legend";
  return 0;
}