#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int z[1000005];
int main() {
  gets(s);
  int ln = strlen(s);
  int j, l = 0, r = 0, b, st;
  for (int i = 1; i < ln; i++) {
    if (i <= r) {
      st = i - l;
      b = r - i + 1;
      if (z[st] < b) {
        z[i] = z[st];
      } else {
        for (j = 1; j < ln && s[r + j] == s[r - i + j]; j++)
          ;
        z[i] = r - i + j;
        l = i;
        r = r + j - 1;
      }
    } else {
      for (j = 0; i + j < ln && s[i + j] == s[j]; j++)
        ;
      l = i;
      r = i + j - 1;
      z[i] = j;
    }
  }
  int res = 0, mx = 0;
  for (int i = ln - 2; i >= 1; i--) {
    st = ln - i - 1;
    mx = max(mx, z[st]);
    if (z[ln - i] == i && mx >= i) {
      res = i;
      break;
    }
  }
  if (res == 0)
    printf("Just a legend\n");
  else
    for (j = 0; j < res; j++) printf("%c", s[j]);
  printf("\n");
  return 0;
}
