#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const long long LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const long long MOD = 1000000007;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const double PI = 3.141592653589793;
inline void open(string a) {
  freopen((a + ".in").c_str(), "r", stdin);
  freopen((a + ".out").c_str(), "w", stdout);
}
inline void fasterios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
struct rollingHash {
  int base, curN;
  bool suffixOn;
  string *myString;
  vector<long long> precBase;
  vector<long long> hash[2];
  explicit rollingHash(string *x, int curBase = 31, bool enableSuffix = 0,
                       bool precomputeBase = 1) {
    myString = x;
    curN = myString->length();
    base = curBase;
    suffixOn = enableSuffix;
    hash[0].resize(curN);
    if (enableSuffix) hash[1].resize(myString->length());
    precBase.resize(curN);
    makeHash();
  }
  void makeHash() {
    if (curN == 0) return;
    precBase[0] = 1;
    for (int i = 1; i < curN; i++) precBase[i] = (precBase[i - 1] * base) % MOD;
    for (int i = 0; i < curN; i++) {
      int curlet = (*myString)[i] - 'a';
      hash[0][i] = (curlet * precBase[curN - i - 1]) % MOD;
      if (i) hash[0][i] = (hash[0][i] + hash[0][i - 1]) % MOD;
      if (suffixOn) {
        hash[1][i] = (curlet * precBase[i]) % MOD;
        if (i) hash[1][i] = (hash[1][i] + hash[1][i - 1]) % MOD;
      }
    }
    return;
  }
  inline long long getHash(int a, int b) {
    bool isSuffix = a > b;
    if (a > b) swap(a, b);
    return (hash[isSuffix][b] - (a - 1 >= 0 ? hash[isSuffix][a - 1] : 0) +
            MOD) %
           MOD;
  }
  bool isSame(pair<int, int> a, pair<int, int> b) {
    if (abs(a.first - a.second) != abs(b.first - b.second)) return 0;
    long long valA = getHash(a.first, a.second);
    long long valB = getHash(b.first, b.second);
    if (a.first <= a.second)
      a = {curN - a.second - 1, curN - a.first - 1};
    else
      swap(a.first, a.second);
    if (b.first <= b.second)
      b = {curN - b.second - 1, curN - b.first - 1};
    else
      swap(b.first, b.second);
    if (a.first > b.first) {
      swap(a, b);
      swap(valA, valB);
    }
    valA = (valA * precBase[b.first - a.first]) % MOD;
    return valA == valB;
  }
  bool isSame(pair<int, int> a, string &s, long long sHash) {
    int sLen = s.length();
    sLen--;
    if (abs(a.first - a.second) != sLen) return 0;
    long long valA = getHash(a.first, a.second);
    if (a.first <= a.second)
      a = {curN - a.second - 1, curN - a.first - 1};
    else
      swap(a.first, a.second);
    sHash = (sHash * precBase[a.first]) % MOD;
    return valA == sHash;
  }
  bool isPalindrome(int a, int b) {
    if (a == b) return 1;
    return isSame({a, b}, {b, a});
  }
};
long long getSingleHash(string &s, long long base = 31) {
  long long ret = 0;
  for (int i = 0; i < s.length(); i++) {
    ret = (ret * base);
    ret = (ret + (s[i] - 'a')) % MOD;
  }
  return ret;
}
int main() {
  fasterios();
  string s;
  cin >> s;
  rollingHash hash1(&s, 31, 0, 1);
  rollingHash hash2(&s, 37, 0, 1);
  rollingHash hash3(&s, 41, 0, 1);
  int n = s.length();
  n--;
  for (int i = n - 2; i >= 0; i--) {
    pair<int, int> a = {0, i};
    pair<int, int> b = {n - i, n};
    if (hash1.isSame(a, b) && hash2.isSame(a, b) && hash3.isSame(a, b)) {
      for (int j = 1;; j++) {
        int kanan = j + i;
        if (kanan == n) break;
        if (hash1.isSame(a, {j, kanan}) && hash2.isSame(a, {j, kanan}) &&
            hash3.isSame(a, {j, kanan})) {
          for (int k = 0; k <= i; k++) cout << s[k];
          cout << '\n';
          return 0;
        }
      }
    }
  }
  cout << "Just a legend" << '\n';
  return 0;
}
