#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 1e6 + 500;
int f[maxn];
int cnt[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  int k = -1;
  f[0] = -1;
  for (int i = 1; i < n; i++) {
    while (s[k + 1] != s[i] && k >= 0) {
      k = f[k];
    }
    if (s[k + 1] == s[i]) k++;
    f[i] = k;
  }
  for (int i = 0; i < n; i++) {
    cnt[f[i]]++;
  }
  k = f[n - 1];
  if (k == -1) {
    cout << "Just a legend";
    return 0;
  }
  if (cnt[k] > 1) {
    cout << s.substr(0, 1 + k);
    return 0;
  }
  k = f[k];
  if (k == -1) {
    cout << "Just a legend";
    return 0;
  }
  cout << s.substr(0, 1 + k);
}
