#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
int main(int argc, const char* argv[]) {
  string input;
  cin >> input;
  vector<int> table(input.size() + 1);
  int i = 0;
  int j = -1;
  int max = 0;
  table[i] = j;
  while (i < input.size()) {
    while (j >= 0 && input[i] != input[j]) j = table[j];
    i++;
    j++;
    table[i] = j;
    if (i < input.size()) {
      max = std::max(max, table[i]);
    }
  }
  table[0] = 0;
  j = table[input.size()];
  while (j > max) {
    j = table[j];
  }
  if (0 == j) {
    cout << "Just a legend" << endl;
  } else {
    cout << input.substr(0, j) << endl;
  }
  return 0;
}
