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