#include <bits/stdc++.h>
using namespace std;
int n, ans;
char s[1000005];
int cnt[1000005];
int len[1000005];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 2, t = 0; i <= n; i++) {
    while (t && s[i] != s[t + 1]) t = len[t];
    if (s[i] == s[t + 1]) t++;
    len[i] = t;
    cnt[t]++;
  }
  ans = len[n];
  if (cnt[ans] < 2) ans = len[ans];
  if (ans == 0) printf("Just a legend");
  for (int i = 1; i <= ans; i++) printf("%c", s[i]);
  printf("\n");
  return 0;
}
