#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 9;
const long long p = 31;
string s;
long long pref[1000005];
long long inv[1000005];
long long suff[1000005];
long long cal[1000005];
long long pw(long long a, long long b) {
  if (b == 0)
    return 1;
  else if (b == 1)
    return a % mod;
  else {
    long long x = pw(a, b / 2);
    if (b % 2 == 0)
      return (x * x) % mod;
    else
      return x * x % mod * a % mod;
  }
}
long long subs(long long l, long long r) {
  return (pref[r] - (l == 0 ? 0 : pref[l - 1]) + mod) % mod * inv[l] % mod;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  long long n = s.size();
  for (long long i = 0; i < 1000005; ++i) {
    if (i == 0)
      cal[i] = 1;
    else
      cal[i] = (cal[i - 1] * p) % mod;
    inv[i] = pw(cal[i], mod - 2);
  }
  for (long long i = 0; i < n; ++i) {
    if (i == 0)
      pref[i] = (s[i] - 'a' + 1) % mod;
    else
      pref[i] = (pref[i - 1] + (s[i] - 'a' + 1) * cal[i]) % mod;
  }
  for (long long j = n - 1; ~j; --j) {
    suff[n - j - 1] = subs(j, n - 1);
  }
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < n - 1; ++i) {
    if (pref[i] == suff[i]) v.push_back(pair<long long, long long>(pref[i], i));
  }
  if (v.empty()) {
    cout << "Just a legend";
    return 0;
  }
  long long ll = 0, mid, ans = -1;
  long long rr = (long long)v.size() - 1;
  bool ok = false, ex = false;
  pair<long long, long long> tmp;
  while (ll <= rr) {
    mid = (rr + ll) / 2;
    ok = false;
    tmp = v[mid];
    for (long long i = 1; i + tmp.second < n - 1; ++i) {
      if (subs(i, i + tmp.second) == tmp.first) {
        ll = mid;
        ok = true;
        ex = true;
        break;
      }
    }
    if (ok) {
      ll = mid + 1;
      if (ans < mid) ans = mid;
    } else
      rr = mid - 1;
  }
  if (!ex) {
    for (long long i = 1; i + v[ans].second < n - 1; ++i) {
      if (subs(i, i + v[ans].second) == v[ans].first) {
        ex = true;
        break;
      }
    }
  }
  if (ex) {
    for (long long i = 0; i <= v[ans].second; ++i) cout << s[i];
  } else
    cout << "Just a legend";
}
