#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int p[1000005];
bool isSuffix[1000005];
int n;
void kmp() {
  int lg = 0;
  p[0] = 0;
  for (int m = 1; m < n; m++) {
    while (lg > 0 && s[lg] != s[m]) lg = p[lg - 1];
    if (s[lg] == s[m]) lg++;
    p[m] = lg;
  }
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  kmp();
  fill(isSuffix, isSuffix + n + 1, false);
  int k = p[n - 1];
  while (k != 0) {
    isSuffix[k] = true;
    k = p[k - 1];
  }
  for (int i = 0; i < n; i++) {
  }
  int maxlen = 0;
  if (p[n - 1] != 0) {
    for (int i = 1; i < n - 1; i++) {
      if (p[i] > maxlen && isSuffix[p[i]]) {
        maxlen = p[i];
      }
    }
  }
  if (maxlen) {
    s[maxlen] = 0;
    printf("%s\n", s);
  } else
    printf("Just a legend\n");
  return 0;
}
