#include <bits/stdc++.h>
#pragma 03
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
vector<long long> h, p;
long long m = 1e9 + 9, po = 31;
signed main() {
  if (fopen(""
            ".INP",
            "r")) {
    freopen(
        ""
        ".INP",
        "r", stdin);
    freopen(
        ""
        ".OUT",
        "w", stdout);
  };
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  cin >> s;
  long long n = s.length();
  h.resize(n, 0);
  p.resize(n, 1);
  long long val = 1;
  long long now = 0;
  for (long long i = 0; i < n; ++i) {
    p[i] = val;
    h[i] = (now + (s[i] - 'a' + 1) * p[i]) % m;
    now = h[i];
    val = (val * po) % m;
  }
  for (long long i = n - 2; i >= 0; --i) {
    if ((h[n - 1] + m - h[n - i - 2]) % m == (h[i] * p[n - i - 1]) % m) {
      for (long long l = 1; l < n - i - 1; ++l) {
        if ((h[i] * p[l]) % m == (h[l + i] + m - h[l - 1]) % m) {
          cout << s.substr(0, i + 1);
          return 0;
        }
      }
    }
  }
  cout << "Just a legend";
  return 0;
}
