#include <bits/stdc++.h>
char s[15000005];
int n, fail[15000005], num[15000005];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int j = 0;
  for (int i = 1; i <= n; i++) {
    for (; j && s[j + 1] != s[i]; j = fail[j])
      ;
    if (s[j + 1] == s[i] && j + 1 != i) j++;
    fail[i] = j;
  }
  for (int i = n; i >= 1; i--) {
    ++num[i];
    num[fail[i]] += num[i];
  }
  while (n) {
    if (num[fail[n]] > 2 && fail[n]) {
      for (int i = 1; i <= fail[n]; i++) printf("%c", s[i]);
      return 0;
    }
    n = fail[n];
  }
  printf("Just a legend\n");
}
