#include <bits/stdc++.h>
using namespace std;
const int NMax = 1000010;
int N;
char A[NMax];
int pi[NMax];
bool viz[NMax];
void Make_Pi() {
  int k = 0;
  pi[1] = 0;
  for (int i = 2; i <= N; ++i) {
    while (k > 0 && A[k + 1] != A[i]) k = pi[k];
    if (A[k + 1] == A[i]) ++k;
    pi[i] = k;
    if (i < N) viz[pi[i]] = true;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> (A + 1);
  N = strlen(A + 1);
  Make_Pi();
  int k = pi[N];
  while (k > 0 && !viz[k]) k = pi[k];
  if (k == 0)
    cout << "Just a legend\n";
  else {
    A[k + 1] = 0;
    cout << (A + 1) << "\n";
  }
  return 0;
}
