#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  string password(const string& s) {
    if (s.empty()) {
      return "Just a legend";
    }
    vector<int> pi(s.size() + 1);
    pi.front() = -1;
    const int n = s.size();
    int i = 0, j = -1;
    while (i < n) {
      if (j == -1 or s.at(i) == s.at(j)) {
        pi.at(++i) = ++j;
      } else {
        j = pi.at(j);
      }
    }
    vector<int> v(s.size() + 1, 0);
    for (i = 1; i <= n; i++) {
      j = pi.at(i);
      while (j > 0 and v.at(j) < 2) {
        v.at(j)++;
        j = pi.at(j);
      }
    }
    j = pi.back();
    while (j > 0) {
      if (v.at(j) >= 2) {
        return s.substr(0, j);
      }
      j = pi.at(j);
    }
    return "Just a legend";
  }
};
int main(void) {
  string s;
  cin >> s;
  Solution solution;
  cout << solution.password(s);
  return 0;
}
