#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 2e9 + 5;
vi pref_func(const string &s) {
  vi p(s.size());
  for (int i = 1, match = 0; i < s.size(); i++) {
    while (match && s[i] != s[match]) match = p[match - 1];
    match += s[i] == s[match];
    p[i] = match;
  }
  return move(p);
}
int main() {
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
  string s;
  cin >> s;
  vi p = pref_func(s);
  vi occ(s.size());
  for (int i = 0; i < s.size() - 1; i++) occ[p[i]]++;
  int match = p.back();
  while (match && occ[match] == 0) match = p[match - 1];
  cout << (match ? s.substr(0, match) : "Just a legend");
  return cout << '\n', 0;
}
