#include <bits/stdc++.h>
char in[1100000];
unsigned long long hs, st[1100000], ed[1100000];
unsigned long long pw[1100000];
int main() {
  int i, j, k, l, m, n, ok, res;
  while (scanf("%s", in) == 1) {
    n = strlen(in);
    res = 0;
    pw[0] = 1;
    for (i = 0; i < n + 1; i++) pw[i + 1] = pw[i] * 10007;
    st[0] = ed[0] = 0;
    for (i = 0; i < n; i++) st[i + 1] = st[i] * 10007 + in[i];
    for (i = 0; i < n; i++) ed[i + 1] = ed[i] + in[n - 1 - i] * pw[i];
    for (k = n - 1; k; k--)
      if (st[k] == ed[k]) {
        ok = 0;
        hs = 0;
        for (i = 0; i < k; i++) hs = hs * 10007 + in[i];
        for (i = k; i < n - 1; i++) {
          hs = hs * 10007 + in[i] - in[i - k] * pw[k];
          if (hs == st[k]) ok = 1;
        }
        if (ok) {
          res = k;
          break;
        }
      }
    if (res > 0) {
      for (i = 0; i < res; i++) putchar(in[i]);
      puts("");
    } else {
      puts("Just a legend");
    }
  }
  return 0;
}
