#include <bits/stdc++.h>
using namespace std;
long long i1, i2, teq = 0, eq[1000050], l1, ans;
string s;
int main() {
  cin >> s;
  l1 = s.length();
  s = ' ' + s;
  for (i1 = 2; i1 <= l1; i1++) {
    while (i2 >= 0) {
      if (s[i1] == s[i2 + 1]) {
        i2++;
        eq[i1] = i2;
        break;
      } else {
        i2 = eq[i2];
        if (!i2) {
          if (s[i1] == s[i2 + 1]) {
            i2++;
            eq[i1] = i2;
          }
          break;
        }
      }
    }
  }
  ans = -1;
  for (i1 = l1 - 1; i1 >= 1; i1--) {
    if (eq[i1] == eq[l1]) {
      ans = eq[l1];
    }
  }
  if (ans == -1) {
    ans = eq[eq[l1]];
  }
  if (ans) {
    for (i1 = 1; i1 <= ans; i1++) {
      cout << s[i1];
    }
  } else {
    cout << "Just a legend";
  }
  return 0;
}
