#include <bits/stdc++.h>
using namespace std;
vector<int> longestPrefix(1000001);
void computePrefix(string str) {
  longestPrefix.push_back(0);
  long long m = str.length();
  for (long long i = 1, k = 0; i < m; i++) {
    while (k > 0 && str[k] != str[i]) {
      k = longestPrefix[k - 1];
    }
    if (str[k] == str[i]) {
      longestPrefix[i] = ++k;
    } else {
      longestPrefix[i] = k;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  computePrefix(s);
  long long found = 0;
  long long len;
  len = longestPrefix[s.length() - 1];
  if (len != 0) {
    for (long long j = 0; j < 2; j++) {
      for (long long i = 1; i < s.length() - 1; i++) {
        if (len == longestPrefix[i]) {
          found = 1;
          break;
        }
      }
      if (!found) {
        len = longestPrefix[len - 1];
        if (len == 0) break;
      } else
        break;
    }
  }
  if (!found || len == 0) {
    cout << "Just a legend";
  } else {
    cout << s.substr(0, len);
  }
}
