#include <bits/stdc++.h>
using namespace std;
constexpr const long long MOD = 1e9 + 7;
string solve(const string &inp) {
  string zstr = inp;
  vector<int> z(zstr.length());
  set<int, greater<int>> suffix;
  int limit = 0;
  for (int i = 1, l = 0, r = 0; i < z.size(); ++i) {
    auto prefix_candidate = z[i - l] < r - i + 1 ? z[i - l] : r - i + 1;
    z[i] = 0 > prefix_candidate ? 0 : prefix_candidate;
    while (z[i] + i < zstr.length() && zstr[z[i]] == zstr[z[i] + i])
      l = i, r = z[i] + i, ++z[i];
    if (z[i] + i == zstr.length()) {
      suffix.insert(z[i]);
      limit = z[i] - 1 > limit ? z[i] - 1 : limit;
    } else
      limit = z[i] > limit ? z[i] : limit;
  }
  auto it = suffix.begin();
  for (; it != suffix.end() && (*it > limit); ++it)
    ;
  if (it != suffix.end() && *it > 0) return inp.substr(0, *it);
  return "Just a legend";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string inp;
  cin >> inp;
  cout << solve(inp) << "\n";
  return 0;
}
