#include <bits/stdc++.h>
using namespace std;
int fail[1010000], c[1010000];
char pat[1010000];
void getnext() {
  int i, k, n;
  i = 0, k = -1;
  n = strlen(pat);
  fail[i] = -1;
  while (i < n) {
    if (k == -1 || pat[i] == pat[k]) {
      ++i;
      ++k;
      fail[i] = k;
    } else
      k = fail[k];
  }
}
int main() {
  int i, j, n, k, ans;
  while (scanf("%s", pat) != EOF) {
    getnext();
    n = strlen(pat);
    for (i = 0; i <= n; i++) {
      c[i] = 0;
    }
    for (i = n; i >= 0; i--) {
      c[fail[i]] += c[i] + 1;
    }
    j = fail[n];
    ans = -1;
    while (j > 0) {
      k = c[j];
      if (k > 1) {
        ans = j;
        break;
      } else
        j = fail[j];
    }
    if (ans > 0) {
      for (i = 0; i < ans; i++) {
        printf("%c", pat[i]);
      }
      printf("\n");
    } else
      printf("Just a legend\n");
  }
  return 0;
}
