#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<int> K;
  K.resize(s.size(), 0);
  K[0] = 0;
  for (int i = 1; i < s.size(); i++) {
    int temp = K[i - 1];
    while (s[temp] != s[i] && temp != 0) temp = K[temp - 1];
    if (s[i] == s[temp])
      K[i] = temp + 1;
    else
      K[i] = 0;
  }
  if (K.back() == 0) {
    cout << "Just a legend";
    return 0;
  }
  int t = K.back();
  for (int i = 0; i < K.size() - 1; i++) {
    if (K[i] == t) {
      cout << s.substr(0, t);
      return 0;
    }
  }
  t = K[t - 1];
  if (t == 0) {
    cout << "Just a legend";
    return 0;
  } else
    cout << s.substr(0, t);
  return 0;
}
