#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int i = 1, j = 0;
  int lps[n];
  lps[0] = 0;
  while (i < n) {
    if (s[i] == s[j]) {
      j++;
      lps[i] = j;
      i++;
    } else {
      if (j != 0)
        j = lps[j - 1];
      else {
        lps[i] = 0;
        i++;
      }
    }
  }
  if (lps[n - 1] == 0) {
    cout << "Just a legend" << endl;
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    if (lps[i] == lps[n - 1]) {
      cout << s.substr(0, lps[n - 1]) << endl;
      return 0;
    }
  }
  if (lps[lps[n - 1] - 1] == 0)
    cout << "Just a legend" << endl;
  else
    cout << s.substr(0, lps[lps[n - 1] - 1]) << endl;
}
