#include <bits/stdc++.h>
using namespace std;
string st;
int z[1000010], len;
char a[1000010];
void z_alg() {
  z[0] = len;
  for (int i = 1, j = 1, k; i < len; i = k) {
    if (j < i) j = i;
    while (j < len && a[j] == a[j - i]) j++;
    z[i] = j - i;
    k = i + 1;
    while (k + z[k - i] < j) z[k] = z[k - i], k++;
  }
}
int main() {
  cin >> a;
  len = strlen(a);
  z_alg();
  for (int i = 1; i < len; i++)
    if (i + z[i] == len)
      for (int j = 1; j < i; j++)
        if (z[j] >= z[i]) {
          cout << (a + i) << endl;
          return 0;
        }
  puts("Just a legend");
  return 0;
}
