#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9;
bool mark[MAX];
int f[MAX], k, n;
int main() {
  string s;
  cin >> s, n = s.size();
  for (int i = 1; i < n; i++) {
    while (k && s[i] != s[k]) k = f[k - 1];
    if (s[i] == s[k]) k++;
    if (i < n - 1) mark[k] = true;
    f[i] = k;
  }
  mark[0] = true, k = f[n - 1];
  while (k && !mark[k]) k = f[k - 1];
  if (k)
    cout << s.substr(0, k);
  else
    cout << "Just a legend";
}
