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;
bool isprime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
vector<long long int> prime;
void sieve(long long int n) {
  bool bakh[n + 1];
  memset(bakh, true, sizeof(bakh));
  for (long long int p = 2; p * p <= n; p++) {
    if (bakh[p] == true) {
      for (long long int i = p * p; i <= n; i += p) bakh[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (bakh[p]) prime.push_back(p);
}
long long int eulertotient(long long int z) {
  long long int fac = z;
  for (long long int i = 0; prime[i] * prime[i] <= z; i++) {
    if (z % prime[i] == 0) {
      fac -= (fac / prime[i]);
      while (z % prime[i] == 0) z /= prime[i];
    }
  }
  if (z > 1) fac -= (fac / z);
  return fac;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  long long int g = gcd(a, b);
  long long int ans = (a * b) / g;
  return ans;
}
long long int modInverse(long long int a, long long int m) {
  long long int hvf = gcd(a, m);
  if (hvf == 1) return power(a, m - 2, m);
  return -1;
}
void multiply(long long int F[2][2], long long int M[2][2]) {
  long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0];
  long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1];
  long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0];
  long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1];
  F[0][0] = x;
  F[0][1] = y;
  F[1][0] = z;
  F[1][1] = w;
}
void powermat(long long int F[2][2], long long int n) {
  if (n == 0 || n == 1) return;
  long long int M[2][2] = {{1, 1}, {1, 0}};
  powermat(F, n / 2);
  multiply(F, F);
  if (n % 2 != 0) multiply(F, M);
}
long long int fib(long long int n) {
  long long int F[2][2] = {{1, 1}, {1, 0}};
  if (n == 0) return 0;
  powermat(F, n - 1);
  return F[0][0];
}
vector<long long int> merge(vector<long long int> v1,
                            vector<long long int> v2) {
  vector<long long int> temp;
  long long int i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    if (v1[i] < v2[j])
      temp.push_back(v1[i]), i++;
    else
      temp.push_back(v2[j]), j++;
  }
  while (i < v1.size()) temp.push_back(v1[i]), i++;
  while (j < v2.size()) temp.push_back(v2[j]), j++;
  return temp;
}
long long int lps[1000005];
void kmplps(string st) {
  long long int p = st.size();
  lps[0] = 0;
  long long int i = 1, l = 0;
  while (i < p) {
    if (st[i] == st[l]) {
      l++;
      lps[i] = l;
      i++;
    } else {
      if (l != 0)
        l = lps[l - 1];
      else
        lps[i] = 0, i++;
    }
  }
}
bool kmpsearch(string pat, string st) {
  bool ms = 0;
  long long int c = 0;
  long long int a = pat.size(), b = st.size();
  kmplps(pat);
  long long int i = 0, j = 0;
  while (i < b) {
    if (pat[j] == st[i]) j++, i++;
    if (j == a) {
      c++;
      if (i == b && c >= 3) ms = 1;
      j = lps[j - 1];
    } else if (i < b && pat[j] != st[i]) {
      if (j != 0)
        j = lps[j - 1];
      else
        i += 1;
    }
  }
  if (c >= 3 && ms) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string st;
  cin >> st;
  long long int n = st.size();
  kmplps(st);
  long long int p = lps[n - 1];
  while (p != 0) {
    string s(st, 0, p);
    if (kmpsearch(s, st)) {
      cout << s << endl;
      return 0;
    }
    p = lps[p - 1];
  }
  cout << "Just a legend" << endl;
}