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 T>
void cmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void cmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
int len(const T &c) {
  return (int)c.size();
}
bool is_palindrome(const string &s, int start, int end) {
  int siz = end - start + 1;
  if (siz % 2 == 0) {
    int middle = start + siz / 2;
    int i;
    for (i = 0; middle - 1 - i >= 0 && middle + i <= end &&
                s[middle - 1 - i] == s[middle + i];
         i++)
      ;
    if (middle - i - 1 < 0 || middle + i > end) return true;
  } else {
    int middle = start + siz / 2;
    int i;
    for (i = 1;
         middle - i >= 0 && middle + i <= end && s[middle - i] == s[middle + i];
         i++)
      ;
    if (middle - i < 0 || middle + i > end) return true;
  }
  return false;
}
int euclidd, euclidx, euclidy;
void extendedeuclid(int a, int b) {
  if (b == 0) {
    euclidd = a;
    euclidx = 1;
    euclidy = 0;
    return;
  }
  extendedeuclid(b, a % b);
  int d1, x1, y1;
  d1 = euclidd;
  x1 = euclidx;
  y1 = euclidy;
  euclidx = y1;
  euclidy = x1 - ((a / b) * y1);
}
double area_triangle(double x1, double y1, double x2, double y2, double x3,
                     double y3) {
  double a;
  a = x1 * (y2 - y3) + y1 * (x3 - x2) + ((x2 * y3) - (y2 * x3)) + 1e-9;
  a = a / 2 + 1e-9;
  return a;
}
double dist_2point(double x1, double y1, double x2, double y2) {
  double d;
  d = sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
  return d;
}
int binary_search(int a[], int n, int l, int u) {
  int mid;
  if (l > u) return 0;
  mid = floor(l + u) / 2;
  if (a[mid] == n)
    return mid;
  else if (a[mid] > n)
    binary_search(a, n, l, mid - 1);
  else
    binary_search(a, n, mid + 1, u);
}
long gcd(long a, long b) {
  while (b > 0) {
    a = a % b;
    a = a ^ b;
    b = b ^ a;
    a = a ^ b;
  }
  return a;
}
long lcm(long a, long b) {
  long x = (a * b) / gcd(a, b);
  return x;
}
long is_prime(long n) {
  long ii;
  if (n == 1) return 0;
  if (n == 2) return 1;
  if (n % 2 == 0) return 0;
  for (ii = 3; ii * ii <= n; ii = ii + 2)
    if (n % ii == 0) return 0;
  return 1;
}
long long bigmod(long long b, long long p, long long m) {
  if (b == 0) return 0;
  long long x, power;
  x = 1;
  power = b % m;
  while (p) {
    if (p % 2 == 1) x = (x * power) % m;
    power = (power * power) % m;
    p = p / 2;
  }
  return x;
}
long ar[1000006];
void kmp(string s) {
  long k, l, i;
  k = 0;
  l = len(s);
  ar[0] = 0;
  for (i = 1; i < l; i++) {
    while (k > 0 && s[k] != s[i]) {
      k = ar[k - 1];
    }
    if (s[k] == s[i]) k++;
    ar[i] = k;
  }
}
bool col[1000006];
int main() {
  string s;
  while (cin >> s) {
    int lim = len(s), i;
    kmp(s);
    memset(col, 0, sizeof(col));
    long p, rs;
    p = ar[lim - 1];
    rs = 0;
    while (p > 0) {
      col[p] = 1;
      p = ar[p - 1];
    }
    for (i = 1; i < lim - 1; i++) {
      if (col[ar[i]]) {
        rs = max(rs, ar[i]);
      }
    }
    if (rs)
      cout << s.substr(0, rs) << endl;
    else
      cout << "Just a legend\n";
  }
  return 0;
}