#include <bits/stdc++.h>
using namespace std;
int n, i, k;
string s1, s2;
int F[1000010];
void kmp(string s) {
  for (i = 1; i < s.size(); i++) {
    while (s[i] != s[k] && k > 0) {
      k = F[k - 1];
    }
    if (s[i] == s[k]) k++;
    F[i] = k;
  }
}
int main() {
  cin >> s1;
  n = s1.size();
  kmp(s1);
  if (F[n - 1] == 0) return cout << "Just a legend", 0;
  for (int i = 0; i < n - 1; i++) {
    if (F[i] == F[n - 1]) {
      for (int j = 0; j < F[i]; j++) cout << s1[j];
      return 0;
    }
  }
  if (F[F[n - 1] - 1] == 0) return cout << "Just a legend", 0;
  for (int j = 0; j < F[F[n - 1] - 1]; j++) cout << s1[j];
  return 0;
}
