#include <bits/stdc++.h>
using namespace std;
vector<int> sublength;
unsigned long long power[1000005], hsh[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  power[0] = 1;
  for (int i = 1; i < 1000005; i++) power[i] = power[i - 1] * 13331;
  string s;
  cin >> s;
  int l = s.size();
  s = '#' + s;
  for (int i = 1; i <= l; i++) {
    hsh[i] = hsh[i - 1] * 13331 + s[i];
  }
  for (int i = 1, j = l; i <= l && j >= 1; i++, j--) {
    unsigned long long pre = hsh[i];
    unsigned long long suf = hsh[l] - hsh[j - 1] * power[l - j + 1];
    if (pre == suf) sublength.push_back(i);
  }
  for (int i = sublength.size() - 1; i >= 0; i--) {
    int p = sublength[i];
    for (int j = 2; j + p - 1 < l; j++) {
      unsigned long long suf = hsh[j + p - 1] - hsh[j - 1] * power[p];
      unsigned long long pre = hsh[p];
      if (suf == pre) {
        cout << s.substr(j, p) << endl;
        return 0;
      }
    }
  }
  cout << "Just a legend" << endl;
}
