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 int N = 1000023;
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a);
    b /= 2;
    a = (a * a);
  }
  return ans;
}
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  if (a.first > b.first)
    return 1;
  else if (a.first == b.first)
    return (a.second < b.second);
  else
    return 0;
}
long long int hash1[N];
long long int p_pow[N];
string str;
long long int n;
void cal_pow() {
  long long int p = 31;
  for (long long int i = 0; i < N; i++) {
    if (i != 0)
      p_pow[i] = (p_pow[i - 1] * p) % 1000000007;
    else
      p_pow[i] = 1;
  }
}
void calc() {
  hash1[0] = str[0] - 'a' + 1;
  for (long long int i = 1; i <= str.size() - 1; i++) {
    hash1[i] = (hash1[i - 1] + (p_pow[i] * (str[i] - 'a' + 1)) % 1000000007) %
               1000000007;
  }
}
long long int check(long long int val, long long int len) {
  for (long long int i = 1; i < n - len; i++) {
    long long int temp =
        (p_pow[n - 1 - i] * (hash1[i + len - 1] - hash1[i - 1] + 1000000007) %
         1000000007) %
        1000000007;
    if (temp == val) return 1;
  }
  return 0;
}
void solve() {
  cin >> str;
  cal_pow();
  calc();
  vector<pair<long long int, long long int>> v;
  n = str.size();
  for (long long int i = 0; i < n - 1; i++) {
    long long int f = (p_pow[n - 1] * hash1[i]) % 1000000007;
    long long int s =
        (p_pow[i] * (hash1[n - 1] - hash1[n - i - 2] + 1000000007) %
         1000000007) %
        1000000007;
    if (f == s) v.push_back({i + 1, f});
  }
  if (!v.size()) {
    cout << "Just a legend" << endl;
    return;
  }
  sort((v).begin(), (v).end());
  v.push_back({n + 3, 1});
  long long int l = 0, r = v.size() - 1;
  if (!check(v[0].second, v[0].first)) {
    cout << "Just a legend" << endl;
    return;
  }
  while ((l + 1) < r) {
    long long int mid = (l + r) / 2;
    if (check(v[mid].second, v[mid].first))
      l = mid;
    else
      r = mid;
  }
  long long int idx = 0, len = v[l].first;
  while (len--) {
    cout << str[idx];
    idx++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int Test;
  Test = 1;
  long long int t = 0;
  while (t++ < Test) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}