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>
const char* INPUTFILE = NULL;
const char* OUTPUTFILE = NULL;
const char* ERROR_LOG__FILE = NULL;
const FILE* INPUT = (INPUTFILE ? freopen(INPUTFILE, "r", stdin) : stdin);
const FILE* OUTPUT = (OUTPUTFILE ? freopen(OUTPUTFILE, "w", stdout) : stdout);
const FILE* ERROR_LOG =
    (ERROR_LOG__FILE ? freopen(ERROR_LOG__FILE, "w", stderr) : stderr);
inline double TIME() {
  return (static_cast<double>(clock())) / (static_cast<double>(CLOCKS_PER_SEC));
}
using namespace std;
const int MAX_SIZE = (1 << 20);
string s;
int pref[MAX_SIZE], suff[MAX_SIZE], size;
class HashString {
 public:
  static const int p = 31;
  unsigned long long pw[MAX_SIZE + 1], h[MAX_SIZE];
  int size;
  inline void build(const string& s) {
    size = (int)s.size();
    h[0] = s[0];
    pw[0] = 1;
    for (int i = 1; i < size; ++i) {
      h[i] = h[i - 1] * p + s[i];
      pw[i] = pw[i - 1] * p;
    }
    pw[size] = pw[size - 1];
  }
  inline unsigned long long get(const int& l, const int& r) const {
    return (l ? h[r] - h[l - 1] * pw[r - l + 1] : h[r]);
  }
  inline bool eq(const int& l1, const int& r1, const int& l2,
                 const int& r2) const {
    return get(l1, r1) == get(l2, r2);
  }
} helper;
inline int find_pref(const int& id) {
  int l, r, mid;
  l = 1;
  r = size - id - 1;
  while (r - l > 1) {
    mid = (l + r) >> 1;
    if (helper.eq(id, id + mid - 1, 0, mid - 1)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  if (helper.eq(id, id + r - 1, 0, r - 1)) {
    return r;
  } else if (helper.eq(id, id + l - 1, 0, l - 1)) {
    return l;
  } else {
    return 0;
  }
}
int ans;
inline void SolveOrDie() {
  cin >> s;
  helper.build(s);
  size = (int)s.size();
  for (int i = 1; i < size - 1; ++i) {
    pref[i] = find_pref(i);
    ans = max(ans, pref[i]);
  }
  for (int i = ans; i >= 1; --i) {
    if (helper.eq(size - i, size - 1, 0, i - 1)) {
      for (int j = 0; j < i; ++j) {
        putchar(s[j]);
      }
      putchar('\n');
      return;
    }
  }
  puts("Just a legend");
}
int main(const int argc, const char** argv) {
  assert(INPUT);
  try {
    SolveOrDie();
  } catch (const std ::exception& e) {
    cerr << e.what() << std ::endl;
    exit(-1);
  } catch (...) {
    cerr << "Exception\n";
    exit(-1);
  }
  return 0;
}