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 <typename T>
T BigMod(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
  return BigMod(b, m - 2, m);
}
template <typename T>
T gcd(T a, T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
char s[1000003];
int z[1000003];
pair<int, int> tree[3 * 1000003];
inline void update(int node, int l, int r, int pos, int val) {
  if (l == r) {
    tree[node].first = val;
    tree[node].second = l;
    return;
  }
  int mid = (l + r) >> 1;
  int lftnode = node << 1;
  int rytnode = lftnode + 1;
  if (pos <= mid)
    update(lftnode, l, mid, pos, val);
  else
    update(rytnode, mid + 1, r, pos, val);
  if (tree[lftnode].first > tree[rytnode].first) {
    tree[node].first = tree[lftnode].first;
    tree[node].second = tree[lftnode].second;
  } else {
    tree[node].first = tree[rytnode].first;
    tree[node].second = tree[rytnode].second;
  }
}
inline pair<int, int> query(int node, int l, int r, int s, int e) {
  if (l == s && r == e) {
    return make_pair(tree[node].first, tree[node].second);
  }
  int mid = (l + r) >> 1;
  int lftnode = node << 1;
  int rghtnode = lftnode + 1;
  if (s > mid)
    return query(rghtnode, mid + 1, r, s, e);
  else if (e <= mid)
    return query(lftnode, l, mid, s, e);
  else {
    pair<int, int> tlft = query(rghtnode, mid + 1, r, mid + 1, e);
    pair<int, int> tryt = query(lftnode, l, mid, s, mid);
    if (tlft.first > tryt.first)
      return tlft;
    else
      return tryt;
  }
}
void Z(int n) {
  int l = 0, r = 0;
  update(1, 1, n, 1, 0);
  for (int i = 1; i < n; i++) {
    z[i] = 0;
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
    update(1, 1, n, i + 1, z[i]);
  }
  return;
}
int main() {
  int i, t, tot, n, j, q, k, st, ed, val, p, x, y, sum, cnt, dif, idx, ind, sz,
      m, l, r, res;
  scanf("%s", &s);
  sz = strlen(s);
  Z(sz);
  int mx = 0;
  for (i = 1; i <= sz - 1; i++) {
    if (z[i] > mx) {
      pair<int, int> tmp = query(1, 1, sz, i + 2, sz);
      int val = tmp.first;
      int idx = tmp.second - 1;
      if (val + idx == sz && val <= z[i]) mx = max(val, mx);
    }
  }
  if (!mx)
    printf("Just a legend");
  else
    for (i = 0; i <= mx - 1; i++) printf("%c", s[i]);
  printf("\n");
  return 0;
}