#include <bits/stdc++.h>
unsigned h[1024000], t;
char s[1024000];
int L, M, i, l;
unsigned p(int x) {
  unsigned r = 1, t = 29;
  for (; x; x >>= 1, t *= t)
    if (x & 1) r *= t;
  return r;
}
int main() {
  gets(s);
  for (t; s[l]; ++l) h[l] = t = t * 29 + s[l];
  for (M = l - 1; M && !L; --M) {
    t = p(M);
    if (h[l - 1] != h[l - 1 - M] * t + h[M - 1]) continue;
    for (i = 0; i + M + 1 < l; ++i)
      if (h[i] * t + h[M - 1] == h[i + M]) L = M;
  }
  s[L] = 0;
  puts(L ? s : "Just a legend");
  return 0;
}
