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