#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 9;
bool done[MAXN];
int pi[MAXN];
string s;
int len;
inline void goF() {
  pi[0] = pi[1] = 0;
  for (int i = 2; i <= len; ++i) {
    char cur = s[i - 1];
    int val = pi[i - 1];
    while (1) {
      if (cur == s[val]) {
        pi[i] = val + 1;
        break;
      }
      if (!val) {
        pi[i] = 0;
        break;
      }
      val = pi[val];
    }
  }
}
int main() {
  memset(done, false, sizeof(done));
  memset(pi, 0, sizeof(pi));
  cin >> s;
  len = (int)s.length();
  goF();
  for (int i = 0; i < len; ++i) {
    done[pi[i]] = true;
  }
  int ans = len;
  while (true) {
    if (done[ans] || (!ans)) break;
    ans = pi[ans];
  }
  if (!ans)
    puts("Just a legend");
  else
    printf("%s\n", s.substr(0, ans).c_str());
  return 0;
}
