#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int ans, a[1000010], z[1000010], n, mx;
int main() {
  gets(s);
  n = 0;
  for (int i = 0; s[i] != '\0'; i++) n++;
  for (int i = 1, l = 0, r = 0; i < n; i++) {
    if (i <= r) {
      z[i] = min(r - i + 1, z[i - l]);
      a[z[i]]++;
    }
    while (s[z[i]] == s[i + z[i]] && i + z[i] < n) {
      z[i]++;
      a[z[i]]++;
    }
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  for (int i = n - 1; i > 0; i--) {
    if (z[i] > mx && i + z[i] == n)
      if (a[z[i]] >= 2) mx = z[i];
  }
  if (mx != 0)
    for (int i = 0; i < mx; i++) cout << s[i];
  else
    cout << "Just a legend";
  cin >> n;
  return 0;
}
