#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.length();
  vector<int> pi(n, 0);
  for (int i = 1; i < n; i++) {
    int j = pi[i - 1];
    while (j > 0 && s[j] != s[i]) j = pi[j - 1];
    if (s[j] == s[i]) j++;
    pi[i] = j;
  }
  vector<int> sub(n + 1, 0);
  for (int i = 0; i < n; i++) sub[pi[i]]++;
  for (int i = n; i > 0; i--) sub[pi[i - 1]] += sub[i];
  int j = n, ch = 0;
  while (j > 0) {
    j = pi[j - 1];
    if (sub[j] > 1 && j) {
      ch = 1;
      break;
    }
  }
  if (ch)
    cout << s.substr(0, j);
  else
    cout << "Just a legend\n";
  cout << "\n";
}
