#include <bits/stdc++.h>
using namespace std;
string s;
int P[1000001], pr[1000001];
int i, j, c;
int main() {
  getline(cin, s);
  if (int((s).size()) <= 2) {
    cout << "Just a legend" << endl;
    return 0;
  }
  pr[0] = 0;
  P[0] = 0;
  for (i = 1; i <= int((s).size()) - 1; i++) {
    j = pr[i - 1];
    while (j > 0 && s[i] != s[j]) j = pr[j - 1];
    if (s[i] == s[j]) j++;
    pr[i] = j;
    P[i] = max(P[i - 1], pr[i]);
  }
  j = pr[int((s).size()) - 1];
  while (j > 0) {
    if (P[int((s).size()) - 2] >= j) {
      for (c = 0; c <= j - 1; c++) cout << s[c];
      cout << endl;
      return 0;
    }
    j = pr[j - 1];
  }
  cout << "Just a legend" << endl;
}
