#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
const int INF = (int)1e7;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
void computeLPSArray(string pat, int M, int* lps) {
  int len = 0;
  lps[0] = 0;
  int i = 1;
  while (i < M) {
    if (pat[i] == pat[len]) {
      len++;
      lps[i] = len;
      i++;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
}
int main() {
  string txt, pat;
  long long i, j, k, M, ans;
  cin >> pat;
  M = pat.size();
  int lps[M];
  computeLPSArray(pat, M, lps);
  ans = lps[M - 1];
  if (ans == 0) {
    cout << "Just a legend" << endl;
    return 0;
  }
  for (i = 1; i < M - 1; i++) {
    if (lps[i] == ans) {
      cout << pat.substr(0, ans) << endl;
      return 0;
    }
  }
  if (lps[ans - 1]) {
    cout << pat.substr(0, lps[ans - 1]);
  } else {
    cout << "Just a legend" << endl;
  }
  return 0;
}
