#include <bits/stdc++.h>
using namespace std;
vector<int> pref(const string& s) {
  int n = s.size();
  vector<int> p(n);
  for (int i = 1; i < n; i++) {
    int j = p[i - 1];
    while (j > 0 && s[i] != s[j]) j = p[j - 1];
    if (s[i] == s[j]) p[i] = j + 1;
  }
  return p;
}
int main() {
  string s;
  cin >> s;
  vector<int> p = pref(s);
  int out = p.back();
  int n = p.size();
  if ((out && find(p.begin(), p.begin() + n - 1, out) != p.begin() + n - 1))
    cout << s.substr(0, out) << endl;
  else if (out && p[out - 1])
    cout << s.substr(0, p[out - 1]) << endl;
  else
    cout << "Just a legend" << endl;
  return 0;
}
