#include <bits/stdc++.h>
#pragma GCC optimize("O2")
const int MAXN = 1e6 + 5;
const int mod = 1e9 + 7;
using namespace std;
int oc[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string a;
  cin >> a;
  vector<int> f((int)a.size());
  int border = 0;
  f[0] = 0;
  for (int i = 1; i < (int)a.size(); i++) {
    while (a[border] != a[i] && border > 0) border = f[border - 1];
    if (a[border] == a[i]) border++;
    f[i] = border;
    oc[border]++;
  }
  if (border && border != (int)a.size() && oc[border] > 1)
    cout << a.substr(0, border);
  else if (border && f[border - 1] != 0)
    cout << a.substr(0, f[border - 1]);
  else
    cout << "Just a legend";
  return 0;
}
