#include <bits/stdc++.h>
using namespace std;
char P[1000110];
int F[1000110];
int N;
void calcula_F() {
  int i, j;
  F[0] = 0;
  j = 0;
  i = 1;
  while (i < N) {
    if (P[i] == P[j]) {
      F[i] = j + 1;
      i++;
      j++;
    } else if (j > 0)
      j = F[j - 1];
    else {
      F[i] = 0;
      i++;
    }
  }
}
int main() {
  scanf("%s", P);
  N = strlen(P);
  calcula_F();
  int n = strlen(P);
  N = n;
  int x = F[n - 1];
  if (x == 0)
    printf("Just a legend\n");
  else {
    int tam1 = F[n - 1];
    int tam2 = F[F[n - 1] - 1];
    int ans = 0;
    for (int i = 1; i < N - 1; i++) {
      if (F[i] % tam1 == 0 && F[i] <= tam1) ans = max(ans, F[i]);
    }
    ans = max(ans, tam2);
    if (ans == 0)
      printf("Just a legend\n");
    else {
      for (int i = 0; i < ans; i++) printf("%c", P[i]);
      printf("\n");
    }
  }
  return 0;
}
