#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, n, m, t;
  string s;
  cin >> s;
  long long int l = 0, r = 0;
  n = s.length();
  long long int z[n];
  z[0] = 0;
  for (i = 1; i < n; i++) {
    if (i > r) {
      l = r = i;
      while (r < n && s[r] == s[r - l]) {
        r += 1;
      }
      z[i] = r - l;
      r -= 1;
    } else {
      k = i - l;
      if (z[k] < r - i + 1)
        z[i] = z[k];
      else {
        l = i;
        while (r < n && s[r] == s[r - l]) {
          r += 1;
        }
        z[i] = r - l;
        r -= 1;
      }
    }
  }
  long long int ma = 0, re = 0;
  for (i = 1; i < n; i++) {
    if (z[i] == n - i && ma >= n - i) {
      re = n - i;
      break;
    }
    ma = max(ma, z[i]);
  }
  if (re == 0) {
    cout << "Just a legend\n";
  } else {
    for (i = 0; i < re; i++) {
      cout << s[i];
    }
  }
  return 0;
}
