#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.length();
  int i, j, l = 0, r = 0;
  vector<int> z(n, 0);
  for (i = 1; i < n; i++) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++;
    if (i + z[i] - 1 > r) {
      l = i;
      r = i + z[i] - 1;
    }
  }
  int mx[n], ans = -1;
  mx[0] = z[0];
  for (i = 1; i < n; i++) mx[i] = max(mx[i - 1], z[i]);
  for (i = n - 1; i > 0; i--) {
    if (i + z[i] == n && mx[i - 1] >= z[i]) ans = i;
  }
  if (ans == -1)
    cout << "Just a legend\n";
  else {
    for (int j = ans; j < n; j++) cout << s[j];
    cout << "\n";
  }
  return 0;
}
