#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = (int)s.length();
  vector<int> pi(n);
  for (int i = 1; i < n; ++i) {
    int j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) ++j;
    pi[i] = j;
  }
  if (pi[n - 1] == 0) {
    printf("Just a legend\n");
    return 0;
  }
  for (int i = 1; i < n - 1; ++i) {
    if (pi[i] == pi[n - 1]) {
      for (int j = n - pi[n - 1]; j < n; ++j) printf("%c", s[j]);
      printf("\n");
      return 0;
    }
  }
  if (pi[pi[n - 1] - 1] == 0)
    printf("Just a legend");
  else
    for (int i = pi[n - 1] - pi[pi[n - 1] - 1]; i < pi[n - 1]; ++i)
      printf("%c", s[i]);
  printf("\n");
  return 0;
}
