#include <bits/stdc++.h>
const int maxn = 1000000 + 10;
char str[maxn];
int fail[maxn], sub[maxn];
bool has[maxn];
int Match(char s[], int p[]) {
  int i, j;
  fail[0] = fail[1] = 0;
  for (i = 1; s[i]; i++) {
    j = fail[i];
    while (j && s[i] != s[j]) j = fail[j];
    fail[i + 1] = (s[i] == s[j] ? j + 1 : 0);
  }
  return i;
}
void Solve() {
  int len = Match(str, fail);
  memset(has, false, sizeof(has));
  for (int i = 0; i < len; i++) has[fail[i]] = true;
  int ans = fail[fail[len]];
  for (int i = fail[len]; i; i = fail[i]) {
    if (has[i]) {
      ans = i;
      break;
    }
  }
  if (ans == 0) {
    printf("Just a legend\n");
  } else {
    printf("%s\n", str + (len - ans));
  }
}
int main() {
  scanf("%s", str);
  Solve();
  return 0;
}
