#include <bits/stdc++.h>
using namespace std;
int n, l, r, z[1000005], a[1000005], ans = -1;
char s[1000005];
int main() {
  gets(s);
  n = strlen(s);
  for (int i = 1; i < n; i++) {
    if (i <= r) z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) {
      l = i;
      r = i + z[i] - 1;
    }
    a[z[i]]++;
  }
  for (int i = n - 1; i >= 0; i--) a[i] += a[i + 1];
  for (int i = 1; i <= n; i++)
    if (a[i] >= 2 && z[n - i] == i) {
      ans = i;
    }
  if (ans == -1)
    puts("Just a legend");
  else
    for (int i = 0; i < ans; i++) printf("%c", s[i]);
  return 0;
}
