#include <bits/stdc++.h>
using namespace std;
void no() {
  cout << "Just a legend\n";
  exit(0);
}
vector<int> prefix_function(string 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;
  }
  return pi;
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (n < 3) no();
  vector<int> pi = prefix_function(s);
  if (pi[n - 1] == 0) no();
  bool gd = false;
  for (int i = 0; i < n - 1; ++i) {
    if (pi[i] == pi[n - 1]) gd = true;
  }
  string ans;
  if (gd) {
    ans = s.substr(0, pi[n - 1]);
  } else {
    if (pi[pi[n - 1] - 1] == 0) no();
    ans = s.substr(0, pi[pi[n - 1] - 1]);
  }
  cout << ans << endl;
  return 0;
}
