#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long pi[1000005];
string p;
void kmp() {
  long long now;
  pi[0] = -1;
  now = -1;
  for (long long i = 1; i < p.size(); i++) {
    while (now != -1 && p[i] != p[now + 1]) now = pi[now];
    if (p[i] == p[now + 1])
      pi[i] = ++now;
    else
      pi[i] = -1;
  }
}
void solve() {
  cin >> p;
  kmp();
  long long len = p.size();
  long long maxi = pi[len - 1];
  long long found = pi[maxi];
  if (maxi == -1) found = -1;
  for (long long i = 1; i < (len - 1); i++) {
    if (pi[i] == maxi) found = maxi;
  }
  if (found == -1)
    cout << "Just a legend" << endl;
  else {
    cout << p.substr(0, found + 1) << endl;
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
