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 y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
long long int max(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
long long int min(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
long long int bins(long long int arr[], long long int l, long long int r,
                   long long int x) {
  if (r >= l) {
    long long int mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] > x) return bins(arr, l, mid - 1, x);
    return bins(arr, mid + 1, r, x);
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  long long int n = s.size();
  int p = 31;
  long long int m = 1000000007;
  vector<long long int> pro(n), h(n + 1, 0);
  pro[0] = 1;
  for (int i = 1; i < n; i++) {
    pro[i] = (pro[i - 1] * p) % m;
  }
  for (int i = 0; i < n; i++) {
    h[i + 1] = (h[i] + (s[i] - 'a' + 1) * pro[i]) % m;
  }
  long long int len = -1;
  for (int l = n - 1; l >= 1; l--) {
    long long int pre, cur, suf;
    pre = (h[l] * pro[n - 1]) % m;
    suf = (h[n] + m - h[n - l]) % m;
    suf = (suf * pro[l - 1]) % m;
    if (pre == suf) {
      for (int i = 1; i <= n - l - 1; i++) {
        cur = (h[i + l] + m - h[i]) % m;
        cur = (cur * pro[n - i - 1]) % m;
        if (cur == suf) {
          len = l;
          break;
        }
      }
    }
    if (len > 0) break;
  }
  if (len < 0)
    cout << "Just a legend";
  else {
    cout << s.substr(0, len);
  }
  return 0;
}