#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
int nex[MAXN], len_pattern, pos, flag;
string pattern;
set<int> s;
void get_next() {
  int i = 0, j = -1;
  nex[0] = -1;
  while (i < len_pattern) {
    if (-1 == j || pattern[i] == pattern[j]) {
      i++;
      j++;
      nex[i] = j;
    } else
      j = nex[j];
  }
}
int main() {
  cin >> pattern, len_pattern = (int)pattern.size();
  get_next();
  int len = len_pattern;
  for (int i = 1; i < len_pattern; i++) s.insert(nex[i]);
  while (0 != nex[len] && -1 != nex[len]) {
    if (s.count(nex[len])) {
      for (int i = 0; i < nex[len]; i++) cout << pattern[i];
      cout << endl;
      flag = 1;
      break;
    }
    len = nex[len];
  }
  if (!flag) cout << "Just a legend" << endl;
  return 0;
}
