#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 2;
long long power[2][N], h[N][2], k, mod[2];
long long match[2][N];
string input;
void precal() {
  mod[0] = 1e9 + 7;
  mod[1] = 1e9 + 9;
  power[0][0] = power[1][0] = 1;
  for (long long i = 1; i <= N - 2; i += 1) {
    power[1][i] = (power[1][i - 1] * 29) % mod[1];
    power[0][i] = (power[0][i - 1] * 29) % mod[0];
  }
}
void Hash(string in) {
  long long cnt;
  for (long long i = 0; i <= 1; i += 1) {
    cnt = 0;
    for (auto v : in) {
      cnt++;
      h[cnt][i] = (h[cnt - 1][i] * 29 + v - 'a' + 1) % mod[i];
    }
  }
}
pair<long long, long long> gethash(long long start, long long end) {
  long long res1 = (h[end][0] - h[start - 1][0] * power[0][end - start + 1] +
                    mod[0] * mod[0]) %
                   mod[0];
  long long res2 = (h[end][1] - h[start - 1][1] * power[1][end - start + 1] +
                    mod[1] * mod[1]) %
                   mod[1];
  return {res1, res2};
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  precal();
  cin >> input;
  Hash(input);
  long long output = 0;
  long long n = input.length();
  for (long long i = 2; i <= n - 1; i += 1) {
    if (input[i - 1] == input[0]) {
      long long low = i, high = n - 1, mid;
      while (low < high) {
        mid = (low + high + (low + high) % 2) / 2;
        if (gethash(i, mid) == gethash(1, mid - i + 1)) {
          low = mid;
        } else {
          high = mid - 1;
        }
      }
      if (high < n) output = max(output, high - i + 1);
    }
  }
  for (long long i = n - 2; i >= 1; i -= 1) {
    if (gethash(1, i) == gethash(n - i + 1, n) && i <= output) {
      for (long long ind = 0; ind <= i - 1; ind += 1) cout << input[ind];
      cout << "\n";
      return 0;
    }
  }
  cout << "Just a legend\n";
}
