#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e6 + 7;
int n, vis[NMAX];
char s[NMAX];
struct LPS {
  int lps[NMAX];
  void build() {
    int i = 0, len = -1;
    lps[i] = len;
    while (i < n) {
      while (len >= 0 && s[i] != s[len]) len = lps[len];
      i++, len++;
      lps[i] = len;
    }
  }
} L;
int main() {
  scanf("%s", s);
  n = strlen(s);
  L.build();
  for (int i = 1; i <= n - 1; i++) vis[L.lps[i]] = 1;
  int go = L.lps[n];
  int res;
  for (; go != 0; go = L.lps[go])
    if (vis[go]) {
      res = go;
      break;
    }
  if (go == 0)
    printf("Just a legend\n") * 0;
  else
    for (int i = 0; i < res; i++) printf("%c", s[i]);
  return 0;
}
