#include <bits/stdc++.h>
using namespace std;
void computeLPSArray(string pat, int M, vector<int> &lps) {
  int len = 0;
  lps[0] = 0;
  int i = 1;
  while (i < M) {
    if (pat[i] == pat[len]) {
      len++;
      lps[i] = len;
      i++;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.length();
  vector<int> lps(n);
  computeLPSArray(s, n, lps);
  int k = lps[lps[n - 1] - 1];
  if (lps[n - 1] == 0) {
    cout << "Just a legend";
    return 0;
  } else {
    int flag = 0;
    for (int j = n - 2; j > 0; j--) {
      if (lps[j] == lps[n - 1]) {
        flag = 1;
        break;
      } else if (lps[j] == k) {
        flag = 2;
      }
    }
    if (flag == 1) {
      cout << s.substr(0, lps[n - 1]);
    } else if (flag == 2) {
      if (k == 0) {
        cout << "Just a legend";
      } else
        cout << s.substr(0, k);
    } else {
      cout << "Just a legend";
    }
  }
  return 0;
}
