#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 500;
const long long INF = 1e13 + 23;
const int MOD = 1e9 + 7;
string s;
int arr[MAXN], mid;
void kmp(string s) {
  for (int i = 1; i < s.size(); i++) {
    int j = arr[i - 1];
    while (s[i] != s[j] && j > 0) j = arr[j - 1];
    if (s[i] == s[j]) ++j;
    arr[i] = j;
    if (i < (int)s.size() - 1) {
      mid = max(mid, j);
    }
  }
}
void solve() {
  cin >> s;
  kmp(s);
  int res = arr[(int)s.size() - 1];
  while (res > mid) {
    res = arr[res - 1];
  }
  if (!res) {
    cout << "Just a legend";
    return;
  }
  string k = "";
  int i = (int)s.size() - 1;
  while (res--) {
    k += s[i];
    i--;
  }
  reverse((k).begin(), (k).end());
  cout << k;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
    cout << '\n';
  }
  return 0;
}
