#include <bits/stdc++.h>
using namespace std;
string s;
bool poklapanje(int x) {
  int n = s.size();
  for (int i = 0; i < x; i++) {
    if (s[i] != s[n - x + i]) return false;
  }
  return true;
}
int main() {
  cin >> s;
  int n = s.size();
  int p[n];
  p[0] = 0;
  for (int i = 1; i < n; i++) {
    int j = p[i - 1];
    while (j > 0 && s[i] != s[j]) j = p[j - 1];
    if (s[i] == s[j]) j++;
    p[i] = j;
  }
  int ans[n];
  for (int i = 0; i < n; i++) ans[i] = 0;
  for (int i = 1; i < n; i++) {
    ans[p[i]]++;
  }
  for (int i = n - 1; i > 0; i--) {
    ans[p[i - 1]] += ans[i];
  }
  int mx = 0;
  for (int i = p[n - 1]; i >= 0; i--) {
    if (ans[i] > 1 && poklapanje(i)) {
      mx = max(mx, i);
      break;
    }
  }
  if (mx == 0) {
    cout << "Just a legend";
  } else {
    for (int i = 0; i < mx; i++) {
      cout << s[i];
    }
  }
  return 0;
}
