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 IO {
template <typename T>
void __RI(T &x) {
  int ch = getchar(), neg = 1;
  x = 0;
  for (; !(isdigit(ch) || ch == '-' || ch == EOF); ch = getchar())
    ;
  if (ch == EOF) return;
  if (ch == '-') neg = -1, ch = getchar();
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
  x *= neg;
}
void R(int &x) { __RI(x); }
void R(int64_t &x) { __RI(x); }
template <typename T1, typename T2>
void R(std::pair<T1, T2> &x) {
  R(x.first);
  R(x.second);
}
template <typename T>
void R(std::vector<T> &x) {
  for (auto &i : x) {
    R(i);
  }
}
template <typename T>
void R(T &x) {
  std::cin >> x;
}
template <typename T, typename... Args>
void R(T &x, Args &...args) {
  R(x), R(args...);
}
template <typename T>
void RA(T *arr, int l, int r) {
  arr += l;
  int p = r - l + 1;
  while (p--) R(*arr++);
}
char space = ' ';
template <typename T>
void __WI(T x) {
  if (x == 0) putchar('0');
  if (x < 0) putchar('-'), x = -x;
  char ch[64];
  int pos = 0;
  while (x) ch[pos++] = x % 10 + 48, x /= 10;
  while (pos) putchar(ch[--pos]);
}
void W() {}
void W(const int &x) { __WI(x); }
void W(const int64_t &x) { __WI(x); }
void W(const double &x) { printf("%lf", static_cast<double>(x)); }
void W(const char &x) { putchar(x); }
void W(const std::string &x) { printf("%s", x.c_str()); }
template <typename T1, typename T2>
void W(const std::pair<T1, T2> &x) {
  W(x.first);
  W(space);
  W(x.second);
}
template <typename T>
void W(const std::vector<T> &x) {
  for (auto it = x.cbegin(); it != x.cend(); it++) {
    W(*it);
    W(space);
  }
  W('\n');
}
template <typename T>
void W(const T &x) {
  std::cout << x;
}
template <typename T, typename... Args>
void W(const T &x, const Args &...args) {
  W(x), W(space), W(args...);
}
template <typename... Args>
void WL(const Args &...args) {
  W(args...), W('\n');
}
template <typename T>
void WA(T *arr, int l, int r, char sp = ' ') {
  arr += l;
  int p = r - l;
  while (p--) W(*arr++), W(sp);
  W(*arr);
}
template <typename T>
void WAL(T *arr, int l, int r) {
  arr += l;
  int p = r - l;
  while (p--) W(*arr++);
  WL(*arr);
}
};  // namespace IO
char t[1000010];
int nxt[1000010], vis[1000010];
int len;
void getnxt() {
  nxt[0] = -1;
  int i = 0, j = -1;
  while (i < len) {
    if (j == -1 || t[i] == t[j])
      i++, j++, nxt[i] = j;
    else
      j = nxt[j];
  }
  for (int i = 0; i < len; i++) vis[nxt[i]]++;
}
int main() {
  IO::R(t);
  len = strlen(t);
  getnxt();
  int j = len;
  bool ok = 0;
  while (nxt[j] != 0) {
    if (vis[nxt[j]]) {
      IO::WAL(t, 0, nxt[j] - 1);
      ok = 1;
      break;
    }
    j = nxt[j];
  }
  if (ok == 0) IO::WL("Just a legend");
  return 0;
}