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;
template <class T1>
void deb(T1 e) {
  cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
template <class T>
inline T sqr(T n) {
  return n * n;
}
template <class T>
T Abs(T x) {
  return (x > 0) ? x : -x;
}
template <class T>
inline double LOG(T a, T b) {
  return (log(a) / log(b));
}
template <class T>
T power(T B, T P) {
  return (P == 0) ? 1 : B * (power(B, (P - 1)));
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
T BigMod(T B, T P, T M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0)
    return sqr((BigMod(B, P / 2, M))) % M;
  else
    return (B % M) * (BigMod(B, P - 1, M)) % M;
}
template <class T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a * (b / GCD(a, b)));
}
int main(void) {
  string a;
  cin >> a;
  int par[(int)a.size() + 5];
  memset(par, 0, sizeof(par));
  par[0] = 0;
  int k = 0;
  int i, j;
  for (i = 1; i < (int)a.size(); i++) {
    while (k > 0 && a[k] != a[i]) k = par[k - 1];
    if (a[k] == a[i]) k++;
    par[i] = k;
  }
  int dp[(int)a.size() + 5];
  for (i = 0; i < (int)a.size() + 5; i++) dp[i] = 1;
  for (i = (int)a.size() - 1; i >= 0; i--) {
    if (par[i] - 1 >= 0) dp[par[i] - 1] += dp[i];
  }
  k = par[(int)a.size() - 1];
  int val = -1;
  while (k > 0) {
    if (dp[k - 1] >= 3) {
      val = k - 1;
      break;
    } else
      k = par[k - 1];
  }
  if (val == -1)
    deb("Just a legend");
  else {
    string res;
    for (j = 0; j < val + 1; j++) res += a[j];
    deb(res);
  }
  return 0;
}