#include <bits/stdc++.h>
using namespace std;
int i, n, k, pref[1000005];
bool u;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  getline(cin, s);
  n = s.length();
  for (i = 1; i < n; ++i) {
    while (k && s[i] != s[k]) k = pref[k - 1];
    if (s[i] == s[k]) ++k;
    pref[i] = k;
  }
  if (!pref[n - 1] || n < 3) return cout << "Just a legend\n", 0;
  for (i = 1; i < n - 1 && !u; ++i)
    if (pref[i] == pref[n - 1]) u = 1;
  if (!u) {
    if (!pref[pref[n - 1] - 1]) return cout << "Just a legend\n", 0;
    for (i = 0; i < pref[pref[n - 1] - 1]; ++i) cout << s[i];
    return 0;
  }
  for (i = 0; i < pref[n - 1]; ++i) cout << s[i];
  return 0;
}
