#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = (int)1e6 + 7, mod = 1000000007, M = 2e9;
int n, rcv[N], t;
bool c[N];
string s;
void fail() {
  int k = 0;
  for (int i = 1; i < n; i++) {
    while (k && s[i] != s[k]) k = rcv[k - 1];
    if (s[i] == s[k]) {
      rcv[i] = ++k;
      c[k] |= i < n - 1;
    }
  }
}
int main() {
  cin >> s;
  n = s.size();
  fail();
  t = rcv[n - 1];
  while (t) {
    if (c[t]) {
      for (int i = 0; i < t; i++) cout << s[i];
      return 0;
    }
    t = rcv[t - 1];
  }
  cout << "Just a legend";
  return 0;
}
