#include <bits/stdc++.h>
using namespace std;
int z[1000010];
char a[1000010];
int main() {
  scanf("%s", &a);
  memset(z, 0, sizeof(z));
  int xx = strlen(a);
  int i, j, k;
  int l = 0, r = 0;
  z[0] = 0;
  z[0] = xx;
  for (int i = 1, l = 0, r = 0; i < xx; ++i) {
    if (l && (i + z[i - l] < r))
      z[i] = z[i - l];
    else {
      int j = min(l ? z[i - l] : 0, i > r ? 0 : r - i);
      while (a[i + j] == a[j]) ++j;
      z[i] = j, l = i, r = i + j;
    }
  }
  int loc = -1, maxi = 0;
  for (i = 1; i < xx; i++) {
    if (z[i] == xx - i && maxi >= z[i]) {
      loc = i;
      maxi = z[i];
      break;
    }
    maxi = max(maxi, z[i]);
  }
  if (loc == -1)
    cout << "Just a legend";
  else {
    for (i = loc; i < (loc + maxi); i++) printf("%c", a[i]);
  }
  return 0;
}
