#include <bits/stdc++.h>
using namespace std;
int z[(int)1e6 + 3];
string z_algo(string s) {
  int x = 0, y = 0;
  int T = 0, M = (int)1e6 + 3;
  for (int i = 1; i < s.size(); i++) {
    z[i] = max(0, min(z[i - x], y - i + 1));
    while (i + z[i] < s.size() && s[z[i]] == s[i + z[i]]) {
      x = i, y = i + z[i];
      z[i]++;
    }
  }
  int maxz = 0, res = 0, n = s.size();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i + z[i] == n && maxz >= z[i]) {
      ans = max(ans, z[i]);
    }
    maxz = max(maxz, z[i]);
  }
  string t;
  for (int i = 0; i < ans; i++) t.push_back(s[i]);
  if (!ans) return "Just a legend";
  return t;
}
int main() {
  int t, tc = 0;
  string s, ans;
  cin >> s;
  ans = z_algo(s);
  cout << ans << endl;
  return 0;
}
