#include <bits/stdc++.h>
using namespace std;
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Set(int N, int pos) { return (N | (1 << pos)); }
long long BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
const int N = 1e6;
int kmp[N + 5];
string str;
void genKMP() {
  int m = str.length(), k;
  kmp[0] = -1;
  for (int i = 1; i <= m; i++) {
    k = kmp[i - 1];
    while (k >= 0) {
      if (str[k] == str[i - 1])
        break;
      else
        k = kmp[k];
    }
    kmp[i] = k + 1;
  }
}
int main() {
  cin >> str;
  genKMP();
  int len = str.size();
  int found = 0;
  string s;
  if (kmp[len] != 0) {
    for (int i = 1; i <= len - 1; i++) {
      if (kmp[i] == kmp[len]) {
        found = 1;
        break;
      }
    }
    if (!found) {
      str = str.substr(len - kmp[len], kmp[len]);
      len = str.size();
      genKMP();
      if (kmp[len] != 0) found = 1;
    }
  }
  if (found) {
    for (int i = 0; i < kmp[len]; i++) cout << str[i];
  } else {
    cout << "Just a legend";
  }
}
