#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t = 1, n, m;
  while (t--) {
    string s;
    cin >> s;
    n = s.length();
    vector<long long> pi(n, 0);
    for (long long i = 1; i < n; i++) {
      long long j = pi[i - 1];
      while (j > 0 && s[i] != s[j]) j = pi[j - 1];
      if (s[i] == s[j]) j++;
      pi[i] = j;
    }
    if (pi[n - 1] == 0) {
      cout << "Just a legend\n";
      continue;
    }
    long long len = 0;
    for (long long i = 0; i < n - 1; i++) {
      if (pi[i] == pi[n - 1]) {
        len = pi[n - 1];
        break;
      }
    }
    if (!len) {
      if (pi[pi[n - 1] - 1]) {
        len = pi[pi[n - 1] - 1];
      }
    }
    cout << (len ? s.substr(0, len) + "\n" : "Just a legend\n");
  }
  return 0;
}
