#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
A cvt(B x) {
  stringstream ss;
  ss << x;
  A y;
  ss >> y;
  return y;
}
string s;
int n;
int cnt(int len, long long h) {
  long long a = 0, p = 1;
  for (int i = 0; i < (int)(len - 1); i++) p = (p * 31) % 1000000007;
  int c = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (i >= len) {
      a = (a - p * (s[i - len] - 'a')) % 1000000007;
      if (a < 0) a += 1000000007;
    }
    a = (a * 31 + (s[i] - 'a')) % 1000000007;
    if (i >= len - 1 && a == h) c++;
  }
  return c;
}
int main() {
  cin >> s;
  n = s.size();
  long long a = 0, b = 0, p = 1;
  vector<pair<int, int> > sizes;
  for (int i = (1); i <= (n - 1); i++) {
    a = (a * 31 + (s[i - 1] - 'a')) % 1000000007;
    b = (b + p * (s[n - i] - 'a')) % 1000000007;
    p = (p * 31) % 1000000007;
    if (a == b) sizes.push_back({i, a});
  }
  int lo = -1, hi = sizes.size();
  while (lo + 1 < hi) {
    int mid = (lo + hi) / 2;
    auto [sz, h] = sizes[mid];
    if (cnt(sz, h) >= 3)
      lo = mid;
    else
      hi = mid;
  }
  if (lo == -1)
    cout << "Just a legend" << endl;
  else
    cout << s.substr(0, sizes[lo].first) << endl;
  return 0;
}
