#include <bits/stdc++.h>
const int MAXN = 1E6 + 10;
int next[MAXN];
char text[MAXN];
void GetNext(const char* p) {
  int j = 0;
  next[0] = next[1] = 0;
  for (int i = 1; p[i]; ++i) {
    while (j && p[i] != p[j]) j = next[j];
    if (p[i] == p[j]) ++j;
    next[i + 1] = j;
  }
}
bool KMP(const char* t, int len_t, const char* p, int len_p) {
  int j = 0;
  for (int i = 0; i < len_t; ++i) {
    while (j && t[i] != p[j]) j = next[j];
    if (t[i] == p[j]) ++j;
    if (j == len_p) return true;
  }
  return false;
}
int main() {
  while (~scanf("%s", text)) {
    GetNext(text);
    int len = strlen(text);
    int j = next[len];
    int ans = 0;
    while (j) {
      if (KMP(text + 1, len - 2, text, j)) {
        ans = j;
        break;
      }
      j = next[j];
    }
    if (ans == 0)
      puts("Just a legend");
    else
      puts(text + len - ans);
  }
}
