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;
const long long mod = 1e9 + 9;
const long long p = 31;
string s;
long long pref[1000005];
long long inv[1000005];
long long suff[1000005];
long long cal[1000005];
long long pw(long long a, long long b) {
  if (b == 0)
    return 1;
  else if (b == 1)
    return a % mod;
  else {
    long long x = pw(a, b / 2);
    if (b % 2 == 0)
      return (x * x) % mod;
    else
      return x * x % mod * a % mod;
  }
}
long long subs(long long l, long long r) {
  return (pref[r] - (l == 0 ? 0 : pref[l - 1]) + mod) % mod * inv[l] % mod;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  long long n = s.size();
  for (long long i = 0; i < 1000005; ++i) {
    if (i == 0)
      cal[i] = 1;
    else
      cal[i] = (cal[i - 1] * p) % mod;
    inv[i] = pw(cal[i], mod - 2);
  }
  for (long long i = 0; i < n; ++i) {
    if (i == 0)
      pref[i] = (s[i] - 'a' + 1) % mod;
    else
      pref[i] = (pref[i - 1] + (s[i] - 'a' + 1) * cal[i]) % mod;
  }
  for (long long j = n - 1; ~j; --j) {
    suff[n - j - 1] = subs(j, n - 1);
  }
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < n - 1; ++i) {
    if (pref[i] == suff[i]) v.push_back(pair<long long, long long>(pref[i], i));
  }
  if (v.empty()) {
    cout << "Just a legend";
    return 0;
  }
  long long ll = 0, mid, ans = -1;
  long long rr = (long long)v.size() - 1;
  bool ok = false, ex = false;
  pair<long long, long long> tmp;
  while (ll < rr) {
    mid = (rr + ll + 1) / 2;
    ok = false;
    tmp = v[mid];
    for (long long i = 1; i + tmp.second < n - 1; ++i) {
      if (subs(i, i + tmp.second) == tmp.first) {
        ll = mid;
        ok = true;
        ex = true;
        break;
      }
    }
    if (ok) {
      ll = mid;
    } else
      rr = mid - 1;
  }
  if (!ex) {
    for (long long i = 1; i + v[ll].second < n - 1; ++i) {
      if (subs(i, i + v[ll].second) == v[ll].first) {
        ex = true;
        break;
      }
    }
  }
  if (ex) {
    for (long long i = 0; i <= v[ll].second; ++i) cout << s[i];
  } else
    cout << "Just a legend";
}