#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int len, b[1000005];
void preprocess() {
  int i = 0, j = -1;
  b[0] = -1;
  while (i < len) {
    while (j >= 0 && s[j] != s[i]) j = b[j];
    i++;
    j++;
    b[i] = j;
  }
}
bool kmp(int i, int l, int len_suffix) {
  int j = 0;
  while (i < l) {
    while (j >= 0 && s[j] != s[i]) j = b[j];
    i++;
    j++;
    if (j == len_suffix) {
      return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%s", &s);
  len = strlen(s);
  preprocess();
  int j = len, idx = -1;
  while (j = b[j]) {
    if (kmp(1, len - 1, j)) {
      idx = j;
      break;
    }
  }
  if (idx == -1)
    puts("Just a legend");
  else {
    for (j = 0; j < idx; ++j) printf("%c", s[j]);
    printf("\n");
  }
  return 0;
}
