#include <bits/stdc++.h>
using namespace std;
int z[1000006] = {0}, h[1000005] = {0};
int main() {
  string s;
  cin >> s;
  int l, r, ma = -1, i;
  l = r = 0;
  for (i = 1; i < s.size(); i++) {
    if (i > r) {
      l = r = i;
      while (s[r - l] == s[r]) r++;
      z[i] = r - l;
      r--;
    } else {
      int k = i - l;
      if (z[k] < r - i + 1)
        z[i] = z[k];
      else {
        l = i;
        while (s[r - l] == s[r]) r++;
        z[i] = r - l;
        r--;
      }
    }
  }
  for (i = 1; i < s.size(); i++)
    if (i + z[i] == s.size()) h[z[i]] = z[i];
  ;
  for (i = 1; i < 1000001; i++)
    if (!h[i]) h[i] = h[i - 1];
  for (i = 1; i < s.size(); i++)
    if (z[i])
      if (z[i] + i == s.size())
        ma = max(ma, h[z[i] - 1]);
      else
        ma = max(ma, h[z[i]]);
  if (ma > 0)
    for (i = 0; i < ma; i++) printf("%c", s[i]);
  else
    printf("Just a legend");
  return 0;
}
