#include <bits/stdc++.h>
using namespace std;
void preFun(string str, vector<long long int>& pi) {
  pi[0] = 0;
  for (long long int i = 1; i < str.size() - 1; ++i) {
    long long int j = pi[i - 1];
    while (j > 0 && str[j] != str[i]) j = pi[j - 1];
    if (str[j] == str[i]) j++;
    pi[i] = j;
  }
}
int main() {
  string str;
  cin >> str;
  if (str.size() == 1) {
    cout << "Just a legend";
    return 0;
  }
  vector<long long int> pi(str.size());
  preFun(str, pi);
  long long int maxi = INT_MIN;
  for (long long int i = 0; i < str.size() - 1; ++i) {
    if (maxi < pi[i]) maxi = pi[i];
  }
  long long int ans = -1;
  long long int j = pi[str.size() - 2];
  while ((str[str.size() - 1] != str[j]) || (j + 1 > maxi)) {
    if (j <= 0) break;
    j = pi[j - 1];
  }
  if (str[j] == str[str.size() - 1]) j++;
  ans = j;
  if (ans == 0 || ans == -1 || ans > maxi) {
    cout << "Just a legend";
  } else
    cout << str.substr(0, ans);
  return 0;
}
