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