#include <bits/stdc++.h>
using namespace std;
char str[1000100];
int zz[1000100], z[1000100];
int len;
void zfunction() {
  int left = 0, right = 0;
  len = strlen(str);
  for (int i = 1; i < len; ++i) {
    if (i > right) {
      left = right = i;
      while (right < len && str[right] == str[right - left]) {
        right++;
      }
      right--;
      zz[i] = right - left + 1;
    } else {
      int tmp = i - left;
      if (zz[tmp] < right - i + 1) {
        zz[i] = zz[tmp];
      } else {
        left = i;
        while (right < len && str[right] == str[right - left]) {
          right++;
        }
        right--;
        zz[i] = right - left + 1;
      }
    }
  }
}
int main() {
  scanf("%s", str);
  zfunction();
  int ans = -1;
  int maxm = 0;
  for (int i = 1; i < len; ++i) {
    if (i == len - zz[i] && zz[i] <= maxm) {
      ans = i;
      break;
    }
    maxm = max(maxm, zz[i]);
  }
  if (ans == -1)
    printf("Just a legend\n");
  else
    printf("%s\n", &str[ans]);
  return 0;
}
