#include <bits/stdc++.h>
using namespace std;
long long base = 255;
const long long mod = 1e9 + 7;
string s;
int n;
vector<int> a;
long long Hash[1000001];
long long pp[1000001];
long long geth(int x, int y) {
  return (Hash[y] - Hash[x - 1] * pp[y - x + 1] + mod * mod) % mod;
}
bool check(int l, int r, long long h, int len) {
  for (int i = l; i <= r - len + 1; i++) {
    long long tmp = geth(i, i + len - 1);
    if (tmp == h) return true;
  }
  return false;
}
void binary() {
  int l = 0, r = a.size() - 1;
  int kq = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    int t = a[mid];
    if (check(2, n - 1, geth(1, a[mid]), a[mid])) {
      kq = a[mid];
      l = mid + 1;
    } else
      r = mid - 1;
  }
  if (kq == -1) {
    cout << "Just a legend";
    return;
  }
  for (int i = 1; i <= kq; i++) cout << s[i];
}
int main() {
  cin >> s;
  n = s.length();
  s = '.' + s;
  pp[0] = 1;
  for (int i = 1; i <= n; i++) {
    pp[i] = (pp[i - 1] * base) % mod;
    Hash[i] = (Hash[i - 1] * base + s[i] - '0') % mod;
  }
  for (int i = 1; i < n; i++) {
    if (geth(1, i) == geth(n - i + 1, n)) {
      a.push_back(i);
    }
  }
  binary();
  return 0;
}
