#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
bool mark[1000010], visit[1000010];
int nexti[1000010];
string s;
int main() {
  cin >> s;
  for (int i = 1; i < (int)s.size(); i++) {
    int tmp = nexti[i - 1];
    while (tmp > 0 && s[i] != s[tmp]) tmp = nexti[tmp - 1];
    if (s[i] == s[tmp]) tmp++;
    nexti[i] = tmp;
  }
  int cur = nexti[(int)s.size() - 1];
  while (cur != 0) {
    mark[cur] = true;
    cur = nexti[cur - 1];
  }
  int ans = 0;
  for (int i = 1; i < (int)s.size() - 1; i++) {
    int cur = nexti[i];
    while (cur > 0 && !mark[cur] && !visit[cur]) {
      visit[cur] = true;
      cur = nexti[cur - 1];
    }
    if (mark[cur]) ans = max(ans, cur);
  }
  if (ans == 0)
    cout << "Just a legend" << endl;
  else
    cout << s.substr(0, ans) << endl;
  return 0;
}
