#include <bits/stdc++.h>
using namespace std;
int build[1000010];
int main() {
  bool f = false;
  string str;
  cin >> str;
  build[0] = -1;
  str += ".";
  for (int i = 0, j = -1; i < str.length();) {
    while (j != -1 && str[i] != str[j]) j = build[j];
    build[++i] = ++j;
  }
  for (int i = build[str.length() - 1]; i > 0 && !f; i = build[i]) {
    for (int j = 1; j < str.length() - 1 && !f; j++) {
      if (build[j] == i) {
        f = true;
        cout << str.substr(0, i) << endl;
      }
    }
  }
  if (!f) cout << "Just a legend" << endl;
  return 0;
}
