#include <bits/stdc++.h>
using namespace std;
string kmp(string s) {
  long long int l = 0, i = 1, n = s.length(), c = 0;
  long long int lps[n];
  string ans;
  lps[0] = 0;
  while (i < n) {
    if (s[i] == s[l]) {
      l++;
      lps[i] = l;
      i++;
    } else {
      if (l == 0) {
        lps[i] = l;
        i++;
      } else
        l = lps[l - 1];
    }
  }
  for (i = 1; i < (n - 1); i++) c = max(c, lps[i]);
  i = n;
  while (i > 0 && lps[i - 1] > c) i = lps[i - 1];
  c = min(c, lps[i - 1]);
  if (c <= 0)
    ans = "Just a legend";
  else
    ans = s.substr(0, c);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    string s;
    cin >> s;
    s = kmp(s);
    cout << s << "\n";
  }
  return 0;
}
