#include <bits/stdc++.h>
using namespace std;
void get_next(int *next, char *substr, int sublen) {
  next[1] = 0;
  int i, j = 0;
  for (i = 2; i <= sublen; ++i) {
    while (j > 0 && substr[j + 1] != substr[i]) j = next[j];
    if (substr[j + 1] == substr[i]) ++j;
    next[i] = j;
  }
}
char str[1000003];
int nxt[1000002];
bool mp[1000002];
int main() {
  int len;
  while (gets(str + 1)) {
    len = strlen(str + 1);
    get_next(nxt, str, len);
    int j = len - 1;
    int ans = -1;
    for (int i = nxt[len]; i != 0; i = nxt[i]) {
      for (int k = i + 1; k <= j; ++k) mp[nxt[k]] = true;
      if (mp[i]) {
        ans = i;
        break;
      }
      j = i;
    }
    if (ans == -1)
      puts("Just a legend");
    else {
      for (int i = 1; i <= ans; ++i) putchar(str[i]);
      putchar('\n');
    }
    memset(mp, 0, sizeof(mp));
  }
  return 0;
}
