#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int __gcd(int a, int b) { return b == 0 ? a : __gcd(b, a % b); }
int power(int x, int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0) {
    int y = power(x, n / 2);
    return y * y;
  } else
    return x * power(x, n - 1);
}
int z[1000010];
int cnt[1000010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  cin >> s;
  int n = s.size(), i, t;
  memset(z, 0, sizeof(z));
  z[0] = 0;
  int l = 0, r = 0;
  for (i = 1; i < n; i++) {
    if (i > r) {
      l = r = i;
      while (r < n && s[r - l] == s[r]) r++;
      z[i] = r - l;
      r--;
    } else {
      int k = i - l;
      if (z[k] < r - i + 1) {
        z[i] = z[k];
      } else {
        l = i;
        while (r < n && s[r - l] == s[r]) r++;
        z[i] = r - l;
        r--;
      }
    }
  }
  int ma = -1, ans = -1;
  for (i = 1; i < n; i++) {
    if (i + z[i] == n && ma >= z[i]) {
      ans = max(z[i], ans);
    }
    ma = max(ma, z[i]);
  }
  if (ans == -1)
    cout << "Just a legend" << '\n';
  else {
    for (i = 0; i < ans; i++) cout << s[i];
    cout << '\n';
  }
}
