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 mult(long long int a, long long int b) {
  return ((a * b) % 1000000007);
}
long long int pow_m(long long int a, long long int p) {
  if (p == 0) {
    return 1;
  } else if (p == 1) {
    return a;
  }
  long long int temp = pow_m(a, p / 2);
  if (p % 2 == 0) {
    return mult(temp, temp);
  } else {
    return mult(mult(temp, temp), a);
  }
}
long long int inv(long long int a) {
  if (a == 0) {
    return 0;
  }
  return pow_m(a, 1000000007 - 2);
}
long long int nChooseK(long long int n, long long int k) {
  if (k == 0) {
    return 1;
  }
  long long int answer = 1;
  for (int i = 0; i < k; ++i) {
    answer = mult(answer, n - i);
  }
  for (int i = 2; i <= k; ++i) {
    answer = mult(answer, inv(i));
  }
  return answer;
}
long long int nChooseK(long long int n, long long int k,
                       vector<long long int>& pre_mult,
                       vector<long long int>& pre_div) {
  if (k == 0) {
    return 1;
  }
  long long int answer = 1;
  answer = mult(answer, pre_mult[n]);
  answer = mult(answer, pre_div[n - k]);
  answer = mult(answer, pre_div[k]);
  return answer;
}
vector<long long int> coordinate_compression(vector<long long int>& input) {
  vector<long long int> b = input;
  sort(b.begin(), b.end());
  map<long long int, long long int> mp;
  for (long long int i = 0; i < b.size(); ++i) {
    if (mp.find(b[i]) == mp.end()) {
      mp[b[i]] = i;
    }
  }
  vector<long long int> answer = input;
  long long int index = 0;
  while (index < b.size()) {
    answer[index] = mp[answer[index]];
  }
  return answer;
}
map<long long int, long long int> get_coordinate_compression_map(
    vector<long long int>& input) {
  vector<long long int> b = input;
  sort(b.begin(), b.end());
  map<long long int, long long int> mp;
  for (long long int i = 0; i < b.size(); ++i) {
    if (mp.find(b[i]) == mp.end()) {
      mp[b[i]] = i;
    }
  }
  return mp;
}
int64_t my_pow(int64_t base, int64_t height) {
  if (height == 0) {
    return 1;
  }
  if (height % 2 == 0) {
    int64_t temp = my_pow(base, height / 2);
    return (temp * temp) % 1000000007;
  } else {
    int64_t temp = my_pow(base, height / 2);
    return ((temp * temp) % 1000000007) * base % 1000000007;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> dp(s.size(), 0);
  int n = s.size();
  int i = 1;
  int length = 0;
  while (i < n) {
    if (s[i] == s[length]) {
      dp[i] = length + 1;
      i++;
      length++;
    } else {
      if (length == 0) {
        dp[i] = 0;
        i++;
      } else {
        length = dp[length - 1];
      }
    }
  }
  if (dp[n - 1] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  string temp = s.substr(0, dp[n - 1]);
  if (temp.size() + 2 <= s.size()) {
    int64_t temp_hash = 0;
    for (int j = 0; j < temp.size(); ++j) {
      temp_hash = (temp_hash * 26 + (temp[j] - 'a')) % 1000000007;
    }
    int64_t current_hash = 0;
    for (int i = 1; i < temp.size() + 1; ++i) {
      current_hash = (current_hash * 26 + (s[i] - 'a')) % 1000000007;
    }
    if (current_hash == temp_hash) {
      cout << temp << "\n";
      return 0;
    }
    for (int i = temp.size() + 1; i < n - 1; ++i) {
      current_hash = (current_hash + 1000000007 -
                      ((s[i - temp.size()] - 'a') *
                       my_pow(26, temp.size() - 1) % 1000000007)) %
                     1000000007;
      current_hash = (current_hash * 26 + (s[i] - 'a')) % 1000000007;
      if (current_hash == temp_hash &&
          s.substr(i - temp.size() + 1, temp.size()) == temp) {
        cout << temp << "\n";
        return 0;
      }
    }
  }
  if (dp[dp[n - 1] - 1] == 0) {
    cout << "Just a legend\n";
    return 0;
  } else {
    cout << s.substr(0, dp[dp[n - 1] - 1]) << "\n";
  }
  return 0;
}