#include <bits/stdc++.h>
char str[1000040];
int len, next[1000040], hash[1000040];
void GetNext() {
  int i = 0, j = -1;
  next[i] = -1;
  while (i < len) {
    if (j == -1 || str[i] == str[j])
      i++, j++, next[i] = j;
    else
      j = next[j];
  }
  for (i = 1; i < len; ++i) hash[next[i]]++;
}
int main() {
  int i, j, k, flag;
  while (scanf("%s", str) != EOF) {
    len = strlen(str);
    memset(hash, 0, sizeof(hash));
    GetNext();
    flag = 0, i = len;
    while (next[i] != 0) {
      if (hash[next[i]]) {
        for (j = 0; j < next[i]; ++j) printf("%c", str[j]);
        flag = 1;
        break;
      }
      i = next[i];
    }
    if (flag == 0) printf("Just a legend");
    printf("\n");
  }
  return 0;
}
