#include <bits/stdc++.h>
using namespace std;
void fill(vector<long long> &lps, string s) {
  long long n = s.size();
  long long i = 1, len = 0;
  while (i < n) {
    if (s[i] == s[len]) {
      len++;
      lps[i++] = len;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        lps[i++] = len;
      }
    }
  }
}
void mymain() {
  string s;
  cin >> s;
  long long n = s.size();
  vector<long long> lps(n, 0);
  fill(lps, s);
  if (lps[n - 1] == 0) {
    cout << "Just a legend" << '\n';
    return;
  }
  for (long long i = 0; i < n - 1; i++) {
    if (lps[i] == lps[n - 1]) {
      cout << s.substr(0, lps[i]) << '\n';
      return;
    }
  }
  if (lps[lps[n - 1] - 1] != 0) {
    cout << s.substr(0, lps[lps[n - 1] - 1]) << '\n';
    return;
  }
  cout << "Just a legend" << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t = 1;
  for (long long tt = 0; tt < t; tt++) {
    mymain();
  }
  return 0;
}
