#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int mod = 1e9 + 7;
char second[N];
int n, ans;
int mx[21][N];
int lg[N];
int get(int l, int r) {
  int z = lg[r - l + 1];
  return max(mx[z][l], mx[z][r - (1 << z) + 1]);
}
void solve() {
  scanf("\n%s", second);
  n = strlen(second);
  vector<int> z(n, 0);
  for (int j = 0, i = 1; i < n; ++i) {
    if (z[j] + j > i) z[i] = min(z[i - j], z[j] + j - i);
    while (z[i] + i < n && second[z[i]] == second[z[i] + i]) z[i]++;
    if (z[i] + i > z[j] + j) j = i;
  }
  z[0] = n;
  for (int i = 1; i <= n; ++i)
    mx[0][i] = z[i - 1], lg[i] = i > 1 ? lg[i >> 1] + 1 : 0;
  for (int k = 1; k <= lg[n]; ++k)
    for (int i = 1; i + (1 << k) - 1 <= n; ++i)
      mx[k][i] = max(mx[k - 1][i], mx[k - 1][i + (1 << (k - 1))]);
  ans = -1;
  for (int i = 1, l, r; i <= n; ++i) {
    l = 2, r = n - i;
    if (r + i - l < i) break;
    if (get(l, r) >= i && z[n - i] == i) ans = i;
  }
  if (ans == -1) {
    printf("Just a legend\n");
    return;
  }
  for (int i = 0; i < ans; ++i) printf("%c", second[i]);
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
