#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int z[1000005], l = -1, r = -1, wynik, indeks;
int out[1000005];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int ile = 0;
  for (int i = 1; n > i; i++) {
    if (r > i) z[i] = min(r - i + 1, z[i - l]);
    while (z[i] + i < n and s[i + z[i]] == s[z[i]]) {
      z[i]++;
      ile++;
    }
    if (z[i] + i - 1 > r) {
      r = z[i] + i - 1;
      l = i;
    }
  }
  int maks = 0;
  for (int i = 1; n - 1 >= i; i++) {
    if (i + z[i] - 1 == n - 1 and maks >= z[i]) {
      wynik = z[i];
      indeks = i;
      break;
    }
    maks = max(maks, z[i]);
  }
  if (wynik == 0) {
    printf("Just a legend");
    return 0;
  }
  for (int i = indeks; wynik + indeks > i; i++) putchar(s[i]);
  return 0;
}
