#include <bits/stdc++.h>
using namespace std;
char s[1000005];
unsigned long long h[10000000];
unsigned long long p[1000001];
int main() {
  unsigned long long h1, h2;
  bool flag = 0;
  stack<int> q;
  scanf("%s", s + 1);
  p[0] = 1;
  for (int i = 1; i <= 1000000; i++) p[i] = p[i - 1] * 33;
  int len = strlen(s + 1);
  for (int i = 1; i <= len; i++) h[i] = h[i - 1] * 33 + s[i];
  for (int i = 1; i < len; i++) {
    h1 = h[i];
    h2 = h[len] - h[len - i] * p[i];
    if (h1 == h2) q.push(i);
  }
  while (q.size() && !flag) {
    int t = q.top();
    for (int i = t + 1; i < len; i++) {
      if (h[t] == h[i] - h[i - t] * p[t]) {
        flag = 1;
        break;
      }
    }
    if (!flag) q.pop();
  }
  if (q.size()) {
    for (int i = 1; i <= q.top(); i++) printf("%c", s[i]);
    printf("\n");
    while (q.size()) q.pop();
  } else {
    printf("Just a legend\n");
  }
  return 0;
}
