#include <bits/stdc++.h>
using namespace std;
int main() {
  int pi[1000005];
  string str;
  int i, n, now = -1;
  cin >> str;
  n = str.length();
  pi[0] = -1;
  for (i = 1; i < n; i++) {
    while (now != -1 && str[i] != str[now + 1]) now = pi[now];
    if (str[i] == str[now + 1])
      pi[i] = ++now;
    else
      pi[i] = now = -1;
  }
  int x = pi[n - 1];
  while (1) {
    if (x == -1) {
      cout << "Just a legend" << endl;
      return 0;
    }
    for (i = 0; i < n - 1; i++) {
      if (pi[i] == x) {
        cout << str.substr(0, x + 1) << endl;
        return 0;
      }
    }
    x = pi[x];
  }
  return 0;
}
