#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
string s;
int prefix[1000005];
bool occured[1000005];
int main() {
  getline(cin, s);
  int N = int((s).size());
  int m = prefix[0] = 0;
  for (int i = (1); i < (N); ++i) {
    while (m > 0 && s[m] != s[i]) m = prefix[m - 1];
    if (s[m] == s[i]) m++;
    prefix[i] = m;
  }
  for (int i = (0); i < (N - 1); ++i) occured[prefix[i]] = true;
  int pos = N;
  while (pos > 0) {
    pos = prefix[pos - 1];
    if (occured[pos] && pos) {
      for (int i = (0); i < (pos); ++i) printf("%c", s[i]);
      return 0;
    }
  }
  printf("Just a legend\n");
  return 0;
}
