#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void solve() {
  string s;
  cin >> s;
  long long n = (long long)((s).size());
  long long lps[n], i = 1, j = 0;
  lps[0] = 0;
  while (i < n) {
    if (s[i] == s[j]) {
      lps[i] = j + 1;
      j++;
      i++;
    } else {
      if (j)
        j = lps[j - 1];
      else {
        lps[i] = 0;
        i++;
      }
    }
  }
  unordered_map<int, int> m;
  for (long long i = 1; i < n - 1; ++i) m[lps[i]] = 1;
  long long val = n;
  while (1) {
    val = lps[val - 1];
    if (val == 0) break;
    if (m[val] == 1) break;
  }
  if (val == 0) {
    cout << "Just a legend";
    return;
  }
  for (long long i = 0; i < val; ++i) cout << s[i];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
