#include <bits/stdc++.h>
using namespace std;
int n, lps[1000005];
bool possible[1000005];
char s[1000005];
void gen_lps() {
  for (int i = 1; i < n; i++) {
    int j = lps[i - 1];
    while (j > 0 && s[j] != s[i]) j = lps[j - 1];
    if (s[j] == s[i]) j++;
    lps[i] = j;
  }
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  gen_lps();
  memset(possible, 0, sizeof(possible));
  for (int i = 0; i < n - 1; i++) possible[lps[i]] = true;
  int len = lps[n - 1];
  while (len > 0 && !possible[len]) {
    len = lps[len - 1];
  }
  if (len)
    for (int i = 0; i < len; i++) printf("%c", s[i]);
  else
    printf("Just a legend");
  return 0;
}
