#include <bits/stdc++.h>
using namespace std;
char save[1000010];
int pre[1000010];
char tmp[1000010];
int tpre[1000010];
void gpre(char *s, int *p) {
  int i, j;
  int len = strlen(s);
  p[0] = -1;
  j = -1;
  for (i = 0; i < len && j < len;) {
    if (j == -1 || s[i] == s[j]) {
      p[++i] = ++j;
    } else {
      j = p[j];
    }
  }
}
int find(char *s, char *x, int *p) {
  int i, j;
  i = j = 0;
  int len = strlen(x);
  int length = strlen(s);
  while (i < length && j < len) {
    if (j == -1 || s[i] == x[j]) {
      i++;
      j++;
    } else {
      j = p[j];
    }
  }
  if (j == len) {
    return i - len;
  }
  return -1;
}
int main() {
  while (scanf("%s", save) != EOF) {
    gpre(save, pre);
    int len = strlen(save);
    if (len == 0) {
      printf("Just a legend\n");
      break;
    }
    int e = pre[len];
    int res = -1;
    while (e) {
      sprintf(tmp, "%s", save + len - e);
      gpre(tmp, tpre);
      int tres = find(save + 1, tmp, tpre);
      if (tres + 1 + e < len) {
        res = tres + 1;
        break;
      }
      e = pre[e];
    }
    if (res != -1) {
      printf("%s\n", save + len - e);
    } else {
      printf("Just a legend\n");
    }
  }
  return 0;
}
