#include <bits/stdc++.h>
using namespace std;
int nxt[1000100], len;
char S[1000100];
bool appear[1000100];
int main() {
  scanf("%s", S + 1);
  len = strlen(S + 1);
  for (int i = 2; i <= len; ++i) {
    int j = nxt[i - 1];
    while (j && S[j + 1] != S[i]) j = nxt[j];
    nxt[i] = j + (S[j + 1] == S[i]);
  }
  for (int i = 2; i < len; ++i) appear[nxt[i]] = 1;
  for (int i = len; i; --i) appear[nxt[i]] |= appear[i];
  int ans = nxt[len];
  while (ans && !appear[ans]) ans = nxt[ans];
  if (ans == 0)
    printf("Just a legend\n");
  else
    S[ans + 1] = 0, printf("%s", S + 1);
  scanf("%s", S + 1);
  return 0;
}
