#include <bits/stdc++.h>
using namespace std;
vector<int> Zfunc(const string& s) {
  int l = 0, r = 0;
  int n = s.size();
  vector<int> z(n, 0);
  for (int i = 1; i < n; i++) {
    z[i] = min(r - i + 1, z[i - l]);
    z[i] = max(z[i], 0);
    while (i + z[i] < n and s[i + z[i]] == s[z[i]]) z[i]++;
    if (i + z[i] - 1 > r) {
      l = i;
      r = i + z[i] - 1;
    }
  }
  return z;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  string t = s;
  t.pop_back();
  vector<int> z = Zfunc(s);
  vector<int> zt = Zfunc(t);
  int n = (int)s.size();
  int maxl = 0;
  for (int i = 1; i < n - 1; i++) maxl = max(maxl, zt[i]);
  int len = 0;
  for (int i = 1; i < n; i++) {
    if (i + z[i] - 1 == n - 1 and z[i] <= maxl and len < z[i]) {
      len = z[i];
    }
  }
  if (!len)
    cout << "Just a legend\n";
  else {
    for (int i = 0; i < len; i++) cout << s[i];
    cout << "\n";
  }
  return 0;
}
