#include <bits/stdc++.h>
using namespace std;
int A[1000000];
int main() {
  string st;
  cin >> st;
  int n = st.size();
  int bordes[n];
  int i = 1, j = 0;
  bordes[0] = 0;
  while (i < n) {
    while (j > 0 && st[i] != st[j]) j = bordes[j - 1];
    if (st[i] == st[j]) j++;
    bordes[i++] = j;
    A[j] += 1;
  }
  int mayor = bordes[n - 1];
  int rpta = 0;
  if (mayor != 0) {
    if (A[mayor] > 1) {
      rpta = mayor;
    } else {
      if (bordes[mayor - 1] != 0) {
        rpta = bordes[mayor - 1];
      }
    }
  }
  if (rpta == 0)
    cout << "Just a legend" << endl;
  else {
    for (int j = 0; j < rpta; j++) {
      cout << st[j];
    }
    cout << endl;
  }
  return 0;
}
