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