#include <bits/stdc++.h>
char s[1000010];
int next_[1000010], vis[1000010];
void getnext() {
  int i = 0, j = -1;
  int len = strlen(s);
  next_[0] = -1;
  while (i < len) {
    if (j == -1 || s[i] == s[j])
      next_[++i] = ++j;
    else
      j = next_[j];
  }
}
int main() {
  int i;
  while (~scanf("%s", s)) {
    int len = strlen(s);
    getnext();
    memset(vis, 0, sizeof(vis));
    for (i = 1; i < len; i++) vis[next_[i]] = 1;
    int j = len, flag = 0;
    while (next_[j] > 0) {
      if (vis[next_[j]]) {
        for (i = 0; i < next_[j]; i++) printf("%c", s[i]);
        printf("\n");
        flag = 1;
        break;
      }
      j = next_[j];
    }
    if (!flag) printf("Just a legend\n");
  }
  return 0;
}
