#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int Z[1000003];
void zAlgorithm(char *S, int n) {
  int g = 0, f = 0;
  Z[0] = 0;
  for (int i = 1; i < n; i++)
    if (i < g && Z[i - f] != (g - i))
      Z[i] = min(Z[i - f], g - i);
    else {
      g = max(g, f = i);
      while (g < n && S[g] == S[g - f]) g++;
      Z[i] = g - f;
    }
}
int main() {
  char cad[1000003];
  scanf("%s", cad);
  int n = strlen(cad);
  zAlgorithm(cad, n);
  int may = 0, sol = 0;
  for (int i = 0; i < n; i++) {
    if (i + Z[i] == n && Z[i] > sol && may >= Z[i]) sol = Z[i];
    if (may < Z[i]) may = Z[i];
  }
  if (sol == 0)
    printf("Just a legend\n");
  else {
    cad[sol] = '\0';
    printf("%s\n", cad);
  }
  return 0;
}
