#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long n = s.length();
  long long p[n];
  p[0] = 0;
  for (long long i = 1; i < n; i++) {
    long long j = p[i - 1];
    while (j > 0 && s[j] != s[i]) {
      j = p[j - 1];
    }
    if (s[j] == s[i]) {
      j++;
    }
    p[i] = j;
  }
  char s1[n];
  for (long long i = n - 1; i >= 0; i--) {
    s1[i] = s[n - 1 - i];
  }
  long long p1[n];
  p1[0] = 0;
  for (long long i = 1; i < n; i++) {
    long long j = p1[i - 1];
    while (j > 0 && s1[j] != s1[i]) {
      j = p1[j - 1];
    }
    if (s1[j] == s1[i]) {
      j++;
    }
    p1[i] = j;
  }
  long long op = 0, ans = p[n - 1];
  for (long long i = 1; i < n - 1; i++) {
    if (p[i] == p1[n - i + p[i] - 2]) {
      ans = min(p[i], p1[n - i + p[i] - 2]);
      if (ans > op) {
        op = ans;
      }
    }
  }
  if (op == 0) {
    cout << "Just a legend";
  }
  for (long long i = 0; i < op; i++) {
    cout << s[i];
  }
  return 0;
}
