#include <bits/stdc++.h>
using namespace std;
const int N = int(1e6) + 1;
char s[N];
int n;
vector<int> p;
bool check(int num) {
  for (int i = 1; i < n - 1; ++i) {
    if (p[i] == num) {
      return true;
    }
  }
  return false;
}
int main(int argc, char *argv[]) {
  scanf("%s", s);
  n = int(strlen(s));
  p.resize(n);
  p[0] = 0;
  for (int i = 1; i < n; ++i) {
    int j = p[i - 1];
    while (j && s[i] != s[j]) {
      j = p[j - 1];
    }
    if (s[i] == s[j]) {
      ++j;
    }
    p[i] = j;
  }
  int ans;
  for (ans = p.back(); ans;) {
    if (check(ans)) {
      break;
    }
    ans = p[ans - 1];
  }
  if (ans) {
    for (int i = 0; i < ans; ++i) {
      printf("%c", s[i]);
    }
  } else {
    printf("Just a legend");
  }
  return 0;
}
