#include <bits/stdc++.h>
using namespace std;
int b[1000006], n, m;
void PF(string P) {
  int i = 0, j = -1;
  b[0] = -1;
  while (i < m) {
    while (j >= 0 && P[i] != P[j]) j = b[j];
    i++;
    j++;
    b[i] = j;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  n = s.length();
  m = n;
  PF(s);
  int maxi = 0;
  for (int i = 2; i < n; ++i) maxi = max(maxi, b[i]);
  if (b[n] == 0) {
    cout << "Just a legend" << '\n';
    return 0;
  }
  if (maxi >= b[n])
    cout << s.substr(0, b[n]) << '\n';
  else if (!b[b[n]])
    cout << "Just a legend" << '\n';
  else
    cout << s.substr(0, b[b[n]]) << '\n';
  return 0;
}
