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 double EPS = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const long long LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const long long MOD = 1000000007;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const double PI = 3.141592653589793;
inline void open(string a) {
  freopen((a + ".in").c_str(), "r", stdin);
  freopen((a + ".out").c_str(), "w", stdout);
}
inline void fasterios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
struct rollingHash {
  int base, curN;
  bool suffixOn;
  string *myString;
  vector<long long> precBase;
  vector<long long> hash[2];
  explicit rollingHash(string *x, int curBase = 31, bool enableSuffix = 0,
                       bool precomputeBase = 1) {
    myString = x;
    curN = myString->length();
    base = curBase;
    suffixOn = enableSuffix;
    hash[0].resize(curN);
    if (enableSuffix) hash[1].resize(myString->length());
    precBase.resize(curN);
    makeHash();
  }
  void makeHash() {
    if (curN == 0) return;
    precBase[0] = 1;
    for (int i = 1; i < curN; i++) precBase[i] = (precBase[i - 1] * base) % MOD;
    for (int i = 0; i < curN; i++) {
      int curlet = (*myString)[i] - 'a';
      hash[0][i] = (curlet * precBase[curN - i - 1]) % MOD;
      if (i) hash[0][i] = (hash[0][i] + hash[0][i - 1]) % MOD;
      if (suffixOn) {
        hash[1][i] = (curlet * precBase[i]) % MOD;
        if (i) hash[1][i] = (hash[1][i] + hash[1][i - 1]) % MOD;
      }
    }
    return;
  }
  inline long long getHash(int a, int b) {
    bool isSuffix = a > b;
    if (a > b) swap(a, b);
    return (hash[isSuffix][b] - (a - 1 >= 0 ? hash[isSuffix][a - 1] : 0) +
            MOD) %
           MOD;
  }
  bool isSame(pair<int, int> a, pair<int, int> b) {
    if (abs(a.first - a.second) != abs(b.first - b.second)) return 0;
    long long valA = getHash(a.first, a.second);
    long long valB = getHash(b.first, b.second);
    if (a.first <= a.second)
      a = {curN - a.second - 1, curN - a.first - 1};
    else
      swap(a.first, a.second);
    if (b.first <= b.second)
      b = {curN - b.second - 1, curN - b.first - 1};
    else
      swap(b.first, b.second);
    if (a.first > b.first) {
      swap(a, b);
      swap(valA, valB);
    }
    valA = (valA * precBase[b.first - a.first]) % MOD;
    return valA == valB;
  }
  bool isSame(pair<int, int> a, string &s, long long sHash) {
    int sLen = s.length();
    sLen--;
    if (abs(a.first - a.second) != sLen) return 0;
    long long valA = getHash(a.first, a.second);
    if (a.first <= a.second)
      a = {curN - a.second - 1, curN - a.first - 1};
    else
      swap(a.first, a.second);
    sHash = (sHash * precBase[a.first]) % MOD;
    return valA == sHash;
  }
  bool isPalindrome(int a, int b) {
    if (a == b) return 1;
    return isSame({a, b}, {b, a});
  }
};
long long getSingleHash(string &s, long long base = 31) {
  long long ret = 0;
  for (int i = 0; i < s.length(); i++) {
    ret = (ret * base);
    ret = (ret + (s[i] - 'a')) % MOD;
  }
  return ret;
}
int main() {
  fasterios();
  string s;
  cin >> s;
  rollingHash hash1(&s, 31, 0, 1);
  rollingHash hash2(&s, 37, 0, 1);
  rollingHash hash3(&s, 41, 0, 1);
  int n = s.length();
  n--;
  for (int i = n - 2; i >= 0; i--) {
    pair<int, int> a = {0, i};
    pair<int, int> b = {n - i, n};
    if (hash1.isSame(a, b) && hash2.isSame(a, b) && hash3.isSame(a, b)) {
      for (int j = 1;; j++) {
        int kanan = j + i;
        if (kanan == n) break;
        if (hash1.isSame(a, {j, kanan}) && hash2.isSame(a, {j, kanan}) &&
            hash3.isSame(a, {j, kanan})) {
          for (int k = 0; k <= i; k++) cout << s[k];
          cout << '\n';
          return 0;
        }
      }
    }
  }
  cout << "Just a legend" << '\n';
  return 0;
}