#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
char s[maxn];
int Next[maxn], n, vis[maxn];
void getNext() {
  Next[0] = Next[1] = 0;
  for (int i = 1; i < n; i++) {
    int j = Next[i];
    while (j && s[i] != s[j]) j = Next[j];
    if (s[i] == s[j])
      Next[i + 1] = j + 1;
    else
      Next[i + 1] = 0;
  }
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  getNext();
  memset(vis, false, sizeof(vis));
  for (int i = 1; i < n; i++) vis[Next[i]] = true;
  int i = n;
  bool flag = false;
  while (Next[i] != 0) {
    if (vis[Next[i]]) {
      for (int j = 0; j < Next[i]; j++) printf("%c", s[j]);
      flag = true;
      break;
    }
    i = Next[i];
  }
  if (!flag) printf("Just a legend\n");
  printf("\n");
  return 0;
}
