#include <bits/stdc++.h>
using namespace std;
const int max_length = 1e6 + 10;
string S;
int z[max_length];
int main() {
  cin >> S;
  for (int i = 1, l = 0, r = 0, cur_max_length = 0; i < (int)S.length(); ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < (int)S.length() && S[z[i]] == S[i + z[i]]) ++z[i];
    if (i + z[i] == (int)S.length() && z[i] <= cur_max_length) {
      for (int j = 0; j < z[i]; ++j) cout << S[j];
      return 0;
    }
    cur_max_length = max(cur_max_length, z[i]);
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  cout << "Just a legend";
  return 0;
}
