#include <bits/stdc++.h>
using namespace std;
string s, s1;
int a[5000100];
int b[5000100];
int calc(int k) {
  int res = 0;
  for (int i = 0; i < s1.length(); ++i) {
    if (b[i] == k) res++;
  }
  return res;
}
void pref(int* mas, int n, string str) {
  int k;
  for (int i = 1; i < str.length(); ++i) {
    k = *(mas + i - 1);
    while (k > 0 && str[i] != str[k]) k = *(mas + k - 1);
    if (str[i] == str[k]) k++;
    *(mas + i) = k;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s;
  pref(a, s.length(), s);
  int maxi = a[s.length() - 1], kol;
  while (maxi > 0) {
    s1 = s.substr(0, maxi) + "$" + s;
    pref(b, s1.length(), s1);
    if (calc(maxi) > 2) {
      cout << s.substr(0, maxi);
      return 0;
    }
    maxi = a[maxi - 1];
  }
  cout << "Just a legend";
  return 0;
}
