#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 100;
int n;
char s[N];
int nx[N];
bool vis[N];
void getnext() {
  nx[0] = -1;
  int i = 0, j = -1;
  while (i < n) {
    if (j == -1 || s[i] == s[j])
      nx[++i] = ++j;
    else
      j = nx[j];
  }
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  getnext();
  for (int i = 1; i < n; i++) vis[nx[i]] = true;
  int ans = nx[n];
  while (!vis[ans] && ans) ans = nx[ans];
  if (ans == 0)
    printf("Just a legend\n");
  else {
    for (int i = 0; i < ans; i++) putchar(s[i]);
    putchar('\n');
  }
  return 0;
}
