#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int N = 1000010;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int nxt[2][N];
void preKMP(char x[], int m, int kmpNext[]) {
  int i = 1, j = kmpNext[1] = 0;
  while (i <= m) {
    while (0 != j && x[i + 1] != x[j + 1]) j = kmpNext[j];
    if (x[j + 1] == x[i + 1]) ++j;
    kmpNext[i + 1] = j;
    ++i;
  }
}
int main() {
  char s[N] = {0};
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  preKMP(s, len, nxt[0]);
  reverse(s + 1, s + 1 + len);
  preKMP(s, len, nxt[1]);
  reverse(s + 1, s + 1 + len);
  int pos = 0, mx = 0;
  for (int i = 1; i <= len; i++)
    if (nxt[0][i] == nxt[1][len - i + nxt[0][i]])
      if (nxt[0][i] > mx) pos = i, mx = nxt[0][i];
  if (pos == 0) {
    cout << "Just a legend" << endl;
  } else {
    for (int i = pos - mx + 1; i <= pos; i++) {
      printf("%c", s[i]);
    }
    puts("");
  }
  return 0;
}
