#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 1000 + 10, mod = 1000 * 1000 * 1000 + 7;
string s;
int i, n, k, p[maxN], ans, m;
long long h1, h2, st;
int main() {
  cin >> s;
  n = s.length();
  if (n < 3) {
    cout << "Just a legend" << endl;
    return 0;
  }
  p[0] = 0;
  for (i = 1; i < n; ++i) {
    k = p[i - 1];
    while (k > 0 && s[i] != s[k]) k = p[k - 1];
    if (s[i] == s[k]) ++k;
    p[i] = k;
  }
  m = 0;
  for (i = 1; i < n - 1; ++i) m = max(m, p[i]);
  ans = 0;
  h1 = h2 = 0;
  st = 1;
  for (i = n - 1; i >= n - m; --i) {
    h1 = (h1 * 101 + s[n - i - 1]) % mod;
    h2 = (h2 + s[i] * st) % mod;
    st = (st * 101) % mod;
    if (h1 == h2) ans = n - i;
  }
  if (ans == 0) {
    cout << "Just a legend" << endl;
  } else {
    for (i = 0; i < ans; ++i) cout << s[i];
    cout << endl;
  }
  return 0;
}
