#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string s;
  cin >> s;
  long long n = s.length();
  vector<long long> lps(n, 0);
  for (long long i = 1; i < n; i++) {
    long long j = lps[i - 1];
    while (j > 0 and s[i] != s[j]) {
      j = lps[j - 1];
    }
    if (s[i] == s[j]) j++;
    lps[i] = j;
  }
  if (lps[n - 1] == 0)
    cout << "Just a legend";
  else {
    for (long long i = 1; i < n - 1; i++) {
      if (lps[i] == lps[n - 1]) {
        cout << s.substr(0, lps[n - 1]);
        exit(0);
      }
    }
    if (lps[lps[n - 1] - 1] == 0)
      cout << "Just a legend";
    else
      cout << s.substr(0, lps[lps[n - 1] - 1]);
  }
}
