#include <bits/stdc++.h>
using namespace std;
int n, i, A[1000001], t;
vector<int> Zfunction(string s) {
  n = s.size();
  vector<int> Z(n, 0);
  int l = 0, r = 0;
  for (i = 1; i < n; i++) {
    if (i <= r) Z[i] = min(r - i + 1, Z[i - l]);
    while (i + Z[i] < n && s[Z[i]] == s[i + Z[i]]) Z[i]++;
    if (i + Z[i] - 1 > r) r = i + Z[i] - 1, l = i;
  }
  return Z;
}
int main() {
  string s;
  cin >> s;
  vector<int> Z(Zfunction(s));
  for (i = 1; i < n; i++) {
    if (Z[i] == n - i && t >= Z[i]) {
      cout << s.substr(0, Z[i]);
      return 0;
    } else
      t = max(t, Z[i] == n - i ? Z[i] - 1 : Z[i]);
  }
  cout << "Just a legend";
}
