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