#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
char s[1000006];
int z[1000006];
void calc_z() {
  int n = (int)strlen(s);
  int l = 0, r = 0;
  for (int i = 1; i <= int(n); i++) {
    if (i < r) {
      z[i] = min(z[i - l], r - i);
    }
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] > r) {
      l = i;
      r = i + z[i];
    }
  }
}
int main() {
  gets(s);
  calc_z();
  int n = (int)strlen(s);
  int len = 0;
  for (int i = 1; i <= int(n - 1); i++) {
    if (i + z[i] < n) {
      len = max(len, z[i]);
    } else {
      len = max(len, z[i] - 1);
    }
  }
  for (int i = 1; i <= int(n - 1); i++) {
    if (i + z[i] == n) {
      if (len >= z[i]) {
        s[z[i]] = 0;
        puts(s);
        return 0;
      }
    }
  }
  cout << "Just a legend\n";
  return 0;
}
