#include <bits/stdc++.h>
using namespace std;
long long p[1000005];
long long mark[1000005];
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, j, n, m, t;
  cin >> s;
  for (i = 1, j = 0; i < s.size(); i++) {
    while (j && s[i] != s[j]) j = p[j - 1];
    if (s[i] == s[j]) {
      j++;
      if (i != s.size() - 1) mark[j] = 1;
    }
    p[i] = j;
  }
  while (j && mark[j] != 1) j = p[j - 1];
  if (j)
    cout << s.substr(0, j);
  else
    cout << "Just a legend" << endl;
}
