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;
namespace AC {
const long long N = 1e5 + 66;
long long BUGS = 1;
inline long long read() {
  long long x = 0;
  bool flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  if (flag) return x;
  return (~(x - 1));
}
inline void read(long long arr[], long long s, long long e) {
  for (long long i = s; i <= e; ++i) arr[i] = read();
}
inline void write(long long x) {
  if (x < 0) {
    x = ~(x - 1);
    putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void print(long long x) {
  write(x);
  puts("");
}
inline void print(long long arr[], long long s, long long e) {
  for (long long i = s; i <= e - 1; ++i) write(arr[i]), putchar(' ');
  write(arr[e]);
  puts("");
}
inline long long max3(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
inline long long min3(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
inline void debugNum(long long num, string ss) {
  cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl;
}
inline void debugArr(long long arr[], long long s, long long e, string ss) {
  cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl;
  for (long long i = s; i <= e; ++i)
    cout << "i : " << i << " val : " << arr[i] << endl;
}
inline void IO() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
}  // namespace AC
using namespace AC;
namespace KMP {
const long long MAXN = 1e6 + 10;
const long long MAXM = 1e4 + 10;
long long prefix[MAXN], pp[MAXN];
vector<long long> ans;
inline void clearKMP() { ans.clear(); }
inline void getNext(long long lenP, long long* prefix, char* p) {
  long long i = 0, k = -1;
  prefix[0] = -1;
  while (i < lenP) {
    if (k == -1 || p[i] == p[k])
      i++, k++, prefix[i] = k;
    else
      k = prefix[k];
  }
}
inline void kmp(long long lenP, long long lenT, long long* prefix, char* p,
                char* txt) {
  getNext(lenP, prefix, p);
  long long i = 0, j = 0;
  while (i < lenT) {
    if (j == -1 || txt[i] == p[j])
      i++, j++;
    else
      j = prefix[j];
    if (j >= lenP) ans.push_back(i - j + 1), j = prefix[j];
  }
}
}  // namespace KMP
using namespace KMP;
char ss[MAXN], p[MAXN];
int main() {
  while (~scanf("%s", ss)) {
    ans.clear();
    long long lenss = strlen(ss);
    getNext(lenss, prefix, ss);
    long long cur = prefix[lenss];
    bool ok = false;
    while (cur > 0) {
      long long lenp = 0;
      for (long long i = 0; i < cur; ++i) {
        p[lenp++] = ss[i];
      }
      p[lenp] = '\0';
      ans.clear();
      kmp(lenp, lenss, pp, p, ss);
      if (ans.size() >= 3) {
        ok = true;
        printf("%s\n", p);
        break;
      } else
        cur = prefix[cur];
    }
    if (ok == false) puts("Just a legend");
  }
  return 0;
}