#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100000;
int f[MAXN];
char s[MAXN];
map<int, int> hsh;
int main() {
  scanf("%s", s);
  int n = strlen(s);
  f[0] = f[1] = 0;
  for (int i = 1; i < n; ++i) {
    int j = f[i];
    while (j && s[i] != s[j]) j = f[j];
    f[i + 1] = s[i] == s[j] ? j + 1 : 0;
  }
  for (int i = 2; i < n; ++i)
    if (f[i] != 0) hsh[f[i] - 1] = 1;
  int x = n;
  while (hsh[f[x] - 1] == 0 && x != 0) x = f[x];
  if (x == 0)
    printf("Just a legend");
  else {
    for (int i = 0; i < f[x]; ++i) printf("%c", s[i]);
  }
  return 0;
}
