#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int n, long long int p) {
  long long int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result % p * x % p) % p;
    x = (x % p * x % p) % p;
    n = n / 2;
  }
  return result % p;
}
void solve() {
  string s;
  cin >> s;
  long long int n = s.length();
  vector<long long int> v1(n), p(n, 1);
  for (long long int i = 1; i <= n - 1; i++)
    p[i] = (p[i - 1] * 31) % 1000000007;
  for (long long int i = 0; i <= n - 1; i++)
    v1[i] = (((long long int)s[i] - 'a' + 1) * p[i]) % 1000000007;
  for (long long int i = 1; i <= n - 1; i++)
    v1[i] = (v1[i - 1] + v1[i]) % 1000000007;
  vector<long long int> v2, v3;
  for (long long int i = 0; i <= n - 3; i++) {
    long long int cur = (v1[i] * p[n - 1 - i]) % 1000000007;
    long long int fin = (v1[n - 1] - v1[n - i - 2] + 1000000007) % 1000000007;
    if (cur == fin) {
      v2.push_back(i);
      v3.push_back(v1[i]);
    }
  }
  if (v2.size() == 0) {
    cout << "Just a legend";
    return;
  }
  reverse(v2.begin(), v2.end());
  reverse(v3.begin(), v3.end());
  vector<long long int> v4;
  for (long long int i = 1; i <= n - 1; i++)
    if (s[i] == s[0]) v4.push_back(i);
  for (long long int i = 0; i <= v2.size() - 1; i++) {
    for (long long int j = 0; j <= v4.size() - 1; j++) {
      if (v4[j] + v2[i] < n - 1) {
        long long int a1 =
            (v1[v4[j] + v2[i]] - v1[v4[j] - 1] + 1000000007) % 1000000007;
        long long int a2 = v3[i] * p[v4[j]] % 1000000007;
        if (a1 == a2) {
          for (long long int k = 0; k <= v2[i]; k++) cout << s[k];
          return;
        }
      }
    }
  }
  cout << "Just a legend";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
