#include <bits/stdc++.h>
using namespace std;
const unsigned long long seed = 131;
const int maxn = 1e6 + 100;
unsigned long long Hash[maxn], P[maxn];
char s[maxn];
int n, cnt, b[maxn], l, r, ans = -1;
void init() {
  P[0] = 1;
  for (int i = 1; i <= n; i++) P[i] = P[i - 1] * seed;
  for (int i = 1; i <= n; i++) {
    Hash[i] = Hash[i - 1] * seed + s[i] - 'a' + 1;
  }
}
unsigned long long get(int l, int r) {
  return Hash[r] - Hash[l - 1] * P[r - l + 1];
}
int ok(int x) {
  for (int i = 2; i + x - 1 < n; i++) {
    if (get(i, i + x - 1) == get(1, x)) return 1;
  }
  return 0;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  init();
  for (int i = 1; i < n; i++) {
    if (get(1, i) == get(n - i + 1, n)) b[cnt++] = i;
  }
  l = 0, r = cnt - 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (ok(b[mid])) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  if (ans == -1)
    puts("Just a legend");
  else {
    for (int i = 1; i <= b[ans]; i++) printf("%c", s[i]);
    puts("");
  }
  return 0;
}
