#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
int n, m, pos, maxL, maxR, maxZ, z[MAX + 1];
char s[MAX + 10];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  if (n < 3) {
    printf("Just a legend");
    return 0;
  }
  for (int i = 2; i <= n; ++i) {
    if (i <= maxR) z[i] = min(z[i - maxL + 1], maxR - i + 1);
    while (i + z[i] <= n && s[1 + z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 == n && maxZ >= z[i] && z[i] > m) {
      m = z[i];
      pos = i;
    }
    maxZ = max(maxZ, z[i]);
    if (i + z[i] - 1 > maxR) {
      maxR = i + z[i] - 1;
      maxL = i;
    }
  }
  if (!m)
    printf("Just a legend");
  else {
    s[pos + m] = '\0';
    printf("%s", s + pos);
  }
  return 0;
}
