#include <bits/stdc++.h>
using namespace std;
char a[1000005];
int z[1000005];
void zalgo(char s[], int n) {
  int L, R, i, j, k;
  L = R = 0;
  for (i = 1; i < n; i++) {
    if (i > R) {
      L = R = i;
      while (R < n && s[R - L] == s[R]) R++;
      z[i] = R - L;
      R--;
    } else {
      k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        L = i;
        while (R < n && s[R - L] == s[R]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
}
int main() {
  int n, i, max1 = -100000000, j;
  scanf("%s", a);
  n = strlen(a);
  zalgo(a, n);
  for (i = 1; i < n; i++) {
    if (z[i] == n - i && max1 >= n - i) {
      for (j = i; j < n; j++) cout << a[j];
      break;
    }
    max1 = max(max1, z[i]);
  }
  if (i == n) cout << "Just a legend";
  cout << "\n";
  return 0;
}
