#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int n = s.length();
  int j = 0, i = 1;
  int prefix[n];
  prefix[0] = 0;
  int k = 0;
  while (i < n) {
    if (s[i] == s[j]) {
      prefix[i] = j + 1;
      i++;
      j++;
    } else {
      if (j != 0)
        j = prefix[j - 1];
      else
        prefix[i] = 0, i++;
    }
  }
  j = prefix[n - 1];
  for (int i = 0; i < n - 1; i++) k = max(k, prefix[i]);
  while (j > 0 && j > k) j = prefix[j - 1];
  if (j)
    cout << s.substr(0, j) << endl;
  else
    cout << "Just a legend\n";
  return 0;
}
