#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int n, z[1000005];
int main() {
  scanf("%s", str);
  n = strlen(str);
  z[0] = n;
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (l && (i + z[i - l] < r))
      z[i] = z[i - l];
    else {
      int j = min(l ? z[i - l] : 0, i > r ? 0 : r - i);
      while (str[i + j] == str[j]) ++j;
      z[i] = j, l = i, r = i + j;
    }
  }
  int maxi = 0, ans = 0;
  for (int i = (1); i < (n); ++i) {
    if (z[i] == n - i && maxi >= n - i) {
      ans = n - i;
      break;
    }
    maxi = max(maxi, z[i]);
  }
  if (ans == 0)
    printf("Just a legend\n");
  else {
    str[ans] = '\0';
    printf("%s\n", str);
  }
  return 0;
}
