#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 123;
const int mod = 1e9 + 7;
const int INF = 1e9 + 1;
const long long INFL = 1e18 + 1;
const double eps = 1e-9;
const double pi = acos(-1.0);
int p[N];
int pw[N], P = 31;
int mult(int a, int b) { return (1ll * a * b) % mod; }
int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int subs(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
struct num {
  int n;
  string second;
  vector<int> h;
  void in() {
    cin >> second;
    n = second.size();
    h.resize(n);
    h[0] = second[0];
    for (int i = 1; i < second.size(); i++) {
      h[i] = add(mult(h[i - 1], P), second[i]);
    }
  }
  int get(int l, int r) {
    if (l > r) return 0;
    if (l == 0) return h[r];
    int res = 0;
    res = subs(h[r], mult(h[l - 1], pw[r - l + 1]));
    return res;
  }
} second, ch;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  second.in();
  pw[0] = 1;
  for (int i = 1; i < second.second.size(); i++) {
    pw[i] = mult(pw[i - 1], P);
  }
  int mx = 0;
  for (int len = second.n - 1; len >= 1; len--) {
    if (second.get(0, len - 1) == second.get(second.n - len, second.n - 1) &&
        len > mx) {
      for (int i = 1; i + len - 1 <= second.second.size() - 2; i++) {
        if (second.get(i, i + len - 1) == second.get(0, len - 1) && len > mx) {
          mx = len;
        }
      }
    }
  }
  if (mx)
    for (int i = 0; i < mx; i++) cout << second.second[i];
  else
    cout << "Just a legend";
  return 0;
}
